SQL oddity.
Posted 09-11-2007 at 06:31 AM by Xandax
I ran into a SQL oddity today - or at least I think it's an oddity.
It revolves around case statements and column aliases, and for some reason you can't use column alias in a case statement. At least neither in the select nor order by clause.
For example:
This works perfetly well.
Now spice it up with a case (for what ever reason)
This for some reason fails because it can't find column C......
I've yet to find the actual reason for why this happens, but that looks odd to me, and it is quite limiting at times.
It revolves around case statements and column aliases, and for some reason you can't use column alias in a case statement. At least neither in the select nor order by clause.
For example:
Code:
SELECT myColumn as C FROM myTable ORDER BY C
Now spice it up with a case (for what ever reason)
Code:
SELECT myCoulmn as C FROM myTable ORDER BY CASE myCondition WHEN myValue THEN C END

I've yet to find the actual reason for why this happens, but that looks odd to me, and it is quite limiting at times.
Total Comments 0
Comments
Recent Blog Entries by Xandax
- Got my GB shirt. (05-24-2008)
- The Pope Speaks (04-17-2008)
- Television is bad for kids .... apparently (11-08-2007)
- Cyclist rant (10-19-2007)
- GrannyStrike (10-03-2007)


