Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

2 Different Names for the Same Field Condition

Status
Not open for further replies.

codrutza

Technical User
Mar 31, 2002
357
IE
Hi
SQL Server Management Studio Express
Maybe it's a silly question.
I have to write in a stored procedure something like that:
select
table.number,
...

case

when table.Company='A'
then table.Ts as TsA

when table.Company<>'A'
then table.Ts as TsnonA

end

from table

I need TsA, TsnonA in the report I'm doing, but I get error at "as".
Could you help me with this?
 
You can't do that. You should have two fields TsA and TsnonA.
Then in Report you should handle them.
Code:
SELECT CASE when table.Company='A'  THEN table.Ts END AS TsA,
       CASE when table.Company<>'A' THEN table.Ts END AS TsNonA
...

BTW I would do this different way.
Get [Ts] and have one field (bit?) that will should you if this TS is from A or NON A:
Code:
SELECT table.Ts,
       CASE when table.Company = 'A' THEN 1 ELSE 0 END AS TsAFlag
...




Borislav Borissov
VFP9 SP2, SQL Server
 
Thanks for reply. I can't modify the tables.
 
I already have the formulas in the report, but I've tried to find an easier, faster way....
 
There is no need to make any changes in the tables, just the resulting query will be with one more field.


Borislav Borissov
VFP9 SP2, SQL Server
 
I wrote in the select and I obtained the field TsAFlag, but I have no idea what to do with it, I'm sorry. The only way I know to use it is in the report maybe.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top