Wednesday, May 04, 2005
WHINING :: Another issues with MS SQL...
Why? Why can't MS SQL allow you to re-use aliases within the same query?
Are there any other DB's that allow you to do this? Or is it simply an issue with SQL Language as a whole?
Here is what I WANT to do:
But in SQL, you have to do this:
That's lame. They should allow you to re-use an alias within your query so that you dont have to do your math longhand EVERY time. This way it's faster to write and less error prone.
Are there any SQL platforms out there that allow this?
*files complaint*
Are there any other DB's that allow you to do this? Or is it simply an issue with SQL Language as a whole?
Here is what I WANT to do:
SELECT colA * (colB + colC) as myField1, myField1 - (colD * colE) as myField2
FROM myTable
But in SQL, you have to do this:
SELECT colA * (colB + colC) as myField1, (colA * (colB + colC) )- (colD * colE) as myField2
FROM myTable
That's lame. They should allow you to re-use an alias within your query so that you dont have to do your math longhand EVERY time. This way it's faster to write and less error prone.
Are there any SQL platforms out there that allow this?
*files complaint*
Comments:
<< Home
SELECT colA * (colB + colC) as myField1, myField1 - (colD * colE) as myField2
FROM myTable
I'm thinking that the reason you're seeing this is because it's all in the same query line. You can't use myField1 as part of your query at this point, because it hasn't been officially designated until the query is completed, no? If that's the case, then what about simply running two consecutive queries (at the risk of increasing the hits on the database of course).
Of course, this is all just a semi-educated guess on my part. Feel free to tell me to shut the hell up and sit down if I wasn't of any help...
FROM myTable
I'm thinking that the reason you're seeing this is because it's all in the same query line. You can't use myField1 as part of your query at this point, because it hasn't been officially designated until the query is completed, no? If that's the case, then what about simply running two consecutive queries (at the risk of increasing the hits on the database of course).
Of course, this is all just a semi-educated guess on my part. Feel free to tell me to shut the hell up and sit down if I wasn't of any help...
well you CAN do sub selects or "virtual tables" but it is a little more taxing and depending on how you write/read your code, it could possibly be more difficult to understand if you were to come back to it.
2 queries, i wouldnt do at all. sub-selects, maybe.
Post a Comment
2 queries, i wouldnt do at all. sub-selects, maybe.
<< Home
