Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2004-05-07 : 11:23:37
|
| Cam writes "I'm trying to reference the results of a calculation in a SELECT statement and can't seem to do it. A simple example is:declare @t table (a int)insert into @t (a) values (1)insert into @t (a) values (2)select Result = case when a = 1 then 1 else 0 end, Result + 1from @tIs there any way of doing this without duplicating the logic of the case statement in calculating the second field? Is there some way I can reference the result that I've already calculated and use it in another column? Thanks for any thoughts,Cam" |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2004-05-07 : 11:34:20
|
| select Result, Result + 1from(select Result = case when a = 1 then 1 else 0 endfrom @t) a==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
|
|
|