alias in case statement

Posted by Alok under Sql Server on 5/8/2012 | Points: 10 | Views : 2847 | Status : [Member] | Replies : 2
i want to use alias in case statemnt but it showing error as ..incorrect syntax near '='

1. select u.acc_status = CASE u.acc_status WHEN '1' THEN 'True' else 'False' END from tblUserLogin u


but below statement show no error..
1. select acc_status = CASE acc_status WHEN '1' THEN 'True' else 'False' END from tblUserLogin u

plz reply..

Thanks & Regards,
Alokssm



Responses

Posted by: Alok on: 5/8/2012 [Member] Starter | Points: 25

Up
0
Down
write 1 statment as

select CASE u.acc_status WHEN '1' THEN 'True' else 'False' END from tblUserLogin u

Thanks & Regards,
Alokssm

Alok, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Pandians on: 5/8/2012 [Member] [MVP] Silver | Points: 25

Up
0
Down
Hi

According to your statement you have used "u.acc_status" as an Alais name. so, you could not use like this
select u.acc_status = CASE u.acc_status WHEN '1' THEN 'True' else 'False' END from tblUserLogin u


So, You have to use either
select acc_status = CASE u.acc_status WHEN '1' THEN 'True' else 'False' END from tblUserLogin u 

--(or)
select CASE u.acc_status WHEN '1' THEN 'True' else 'False' END as acc_status from tblUserLogin u



Cheers
www.SQLServerbuddy.blogspot.com
iLink Multitech Solutions

Alok, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response