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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Help with Case

Author  Topic 

qman
Constraint Violating Yak Guru

442 Posts

Posted - 2009-03-04 : 08:11:49
How can I read one column and based on its value, populate an aliased column (does not exist in the table), which will be used to create a csv file?

I assume CASE will do it, just not sure of the syntax when assigning the values to the aliased field.

SELECT
CASE
WHEN service_code = 'Regular Inquiries' THEN test = 'Checking Service'
ELSE test = 'Testing'
END AS test, service_code FROM data_cert_template

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-03-04 : 08:15:10
SELECT
CASE
WHEN service_code = 'Regular Inquiries' THEN 'Checking Service'
ELSE 'Testing'
END AS test FROM data_cert_template
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-03-04 : 08:16:56
or

SELECT
test=CASE
WHEN service_code = 'Regular Inquiries' THEN 'Checking Service'
ELSE 'Testing'
END , service_code FROM data_cert_template


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

qman
Constraint Violating Yak Guru

442 Posts

Posted - 2009-03-04 : 08:25:15
Great, thanks guys.
madhivanan...., just what I was looking for!
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-03-04 : 09:07:54
quote:
Originally posted by qman

Great, thanks guys.
madhivanan...., just what I was looking for!

You are welcome

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -