• If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Announcement

Collapse
No announcement yet.

Order by can only contain column or alias names

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Order by can only contain column or alias names

    I got this popup while trying to use a case statement in an order by clause. Statement works great in ACS. Is there another way to get this done?
    I'm trying to order by date but I also have '0001-01-01' dates that I want at the bottom. My order by looks like this.
    case when expirationdate = '0001-01-01' then 1 else 0 end,
    expirationDate

  • #2
    Try making your case statement a column, then include that column name in the order by. Like this:

    Code:
    Select col1,
           col2,
           expDate,
           case when expDate='0001-01-01' then 1 else 0 end as nullSort
      from filename
     order by nullSort, expDate

    Comment


    • #3
      Thanks Robert, that worked.
      How come I can't do it like I can do it with Run SQL Scripts?

      Comment


      • #4
        I believe it's because NAB needs named references in the Order By clause.

        Comment

        Working...
        X