0

I had problem while executing this SQL statement in MySQL workbench. Can anyone point out the problem for me?

SELECT concat(LocationName,' - ', StationName) AS LocationStation, EmpName AS '0000-0100', EmpName AS '0100-0200', EmpName AS '0200-0300', EmpName AS '0300-0400', EmpName AS '0400-0500', EmpName AS '0500-0600', EmpName AS '0600-0700', EmpName AS '0700-0800', EmpName AS '0800-0900', EmpName AS '0900-1000', EmpName AS '1000-1100', EmpName AS '1100-1200', FROM satsschema.employeeslot
WHERE LocationName = 'T2 PML'
and AllocationDate = '10-Aug' 
and (EmpTime >= '00:00:00' and EmpTime <= '12:00:00')

The above statemnt prompted me this error, "You have an error in your SQL syntax, check the manual that corresponds to your MySQL server version for the right syntax to use neat 'FROM satsschema.employeeslot WHERE LocationName = 'T2 PML' and AllocationDate = ' at line 1."

Secondly, Is there any other ways that could make this line shorter besides typing everything out?

EmpName AS '0000-0100', EmpName AS '0100-0200', EmpName AS '0200-0300', EmpName AS '0300-0400', EmpName AS '0400-0500', EmpName AS '0500-0600', EmpName AS '0600-0700', EmpName AS '0700-0800', EmpName AS '0800-0900', EmpName AS '0900-1000', EmpName AS '1000-1100', EmpName AS '1100-1200', FROM satsschema.employeeslot

Help will be greatly appreciated.

3
  • 1
    try removing the ',' before the FROM Commented Aug 29, 2012 at 6:28
  • What's the point in giving more than one alias to one column ? Commented Aug 29, 2012 at 6:32
  • The 1hour break time indicates the header and the values inside will be the employees that were working in the time slot. Commented Aug 29, 2012 at 6:35

2 Answers 2

1

Remove the comma before FROM. It causes the error.

SELECT concat(LocationName,' - ', StationName) AS LocationStation, EmpName AS '0000-0100', EmpName AS '0100-0200', EmpName AS '0200-0300', EmpName AS '0300-0400', EmpName AS '0400-0500', EmpName AS '0500-0600', EmpName AS '0600-0700', EmpName AS '0700-0800', EmpName AS '0800-0900', EmpName AS '0900-1000', EmpName AS '1000-1100', EmpName AS '1100-1200' FROM satsschema.employeeslot
WHERE LocationName = 'T2 PML'
and AllocationDate = '10-Aug' 
and (EmpTime >= '00:00:00' and EmpTime <= '12:00:00')

Note that the error message said exactly where was the error.

In MySQL, the AS keyword is optional for column aliasing, so you may write EmpName '0000-0100' in place of EmpName AS '0000-0100'. I don't think there is a short solution to give more than one alias to one column as it's really not something that is often necessary.

Sign up to request clarification or add additional context in comments.

1 Comment

Yep I understand but giving more then 1 alias in this case for me is to let the user know which employees falls inside the time slot. It's like a schedule.
0

Remove extra comma before from clause.

SELECT  concat(LocationName,' - ', StationName) AS LocationStation, 
        EmpName AS '0000-0100', 
        EmpName AS '0100-0200', 
        EmpName AS '0200-0300', 
        EmpName AS '0300-0400', 
        EmpName AS '0400-0500', 
        EmpName AS '0500-0600',
        EmpName AS '0600-0700', 
        EmpName AS '0700-0800', 
        EmpName AS '0800-0900', 
        EmpName AS '0900-1000', 
        EmpName AS '1000-1100',
        EmpName AS '1100-1200'   -- remove comma here
FROM satsschema.employeeslot
WHERE LocationName = 'T2 PML'
and AllocationDate = '10-Aug' 
and (EmpTime >= '00:00:00' and EmpTime <= '12:00:00')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.