General information
Forum:
Microsoft SQL Server
>In VFP you can do this
>
>Select somefield+somethingelse as mycalcfield from mytable where mycalcfield>10
>
>in T-SQL it seems you have to do this
>Select somefield+somethingelse as mycalcfield from mytable where somefield+somethingelse>10
>
>which means you have to maintain both calcfield expressions which is a maintenance headache
>
>Is there a way in T-SQL to use the calcfield alias in the where expression?
You can also use CROSS APPLY:
SELECT MyCalcField
FROM MyTable
CROSS APPLY (SELECT SomeField+SomethingElse AS MyCalcField) F
WHERE MyCalcField>10
That will produce the same query plan as the query you wrote above.
--Brad
Previous
Next
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only