locked
Error Code: 1054. Unknown column 'StartDate' in 'order clause' RRS feed

  • Question

  • User2014201474 posted

    The below is my sql statement, but it pop out error in mtsql

    can tell me what the error?

    Select RECID,'1' AS Seqno,'1' AS ScheduleContinues,MessageDirection 
    FROM tblBranch_Schedule WHERE DATEDIFF('2011-07-07', StartDate) > 0 AND DATEDIFF(EndDate, '2011-07-07')>= 0 
    AND BranchRECID = 'b6a2edf0-1ff1-4b21-8121-30a0197b33ea' UNION 
    Select RECID,'2' AS Seqno,ScheduleContinues,MessageDirection 
    FROM tblBranch_Schedule a where BranchRECID = 'b6a2edf0-1ff1-4b21-8121-30a0197b33ea' Order by StartDate DESC

    I got the below error

    Error Code: 1054. Unknown column 'StartDate' in 'order clause'

    Thursday, July 7, 2011 3:39 AM

Answers

  • User2014201474 posted
    (Select RECID,'1' AS Seqno,'1' AS ScheduleContinues,MessageDirection 
    FROM tblBranch_Schedule WHERE DATEDIFF('2011-07-07', StartDate) > 0 AND DATEDIFF(EndDate, '2011-07-07')>= 0 
    AND BranchRECID = 'b6a2edf0-1ff1-4b21-8121-30a0197b33ea') UNION 
    (Select RECID,'2' AS Seqno,ScheduleContinues,MessageDirection 
    FROM tblBranch_Schedule a where BranchRECID = 'b6a2edf0-1ff1-4b21-8121-30a0197b33ea' Order by StartDate DESC)

    Insert () in two select statement
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, July 7, 2011 4:12 AM

All replies

  • User-1516073966 posted

    Does your table "tblBranch_Schedule" has the column "StartDate" ?

    Thursday, July 7, 2011 3:44 AM
  • User2014201474 posted

    got, if comment for the union, both select oso got result

    Thursday, July 7, 2011 3:54 AM
  • User2014201474 posted
    (Select RECID,'1' AS Seqno,'1' AS ScheduleContinues,MessageDirection 
    FROM tblBranch_Schedule WHERE DATEDIFF('2011-07-07', StartDate) > 0 AND DATEDIFF(EndDate, '2011-07-07')>= 0 
    AND BranchRECID = 'b6a2edf0-1ff1-4b21-8121-30a0197b33ea') UNION 
    (Select RECID,'2' AS Seqno,ScheduleContinues,MessageDirection 
    FROM tblBranch_Schedule a where BranchRECID = 'b6a2edf0-1ff1-4b21-8121-30a0197b33ea' Order by StartDate DESC)

    Insert () in two select statement
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, July 7, 2011 4:12 AM