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 |
|
buckeyeJane
Starting Member
11 Posts |
Posted - 2011-06-16 : 12:38:20
|
| Hello - I have a select statement that is pulling information that I need. However, I need to add aliased columns and set the value on the fly during the select statement. For instance, the customer id is < 0, I would need the aliased column to state "Hidden" for that particular row. How can this be accomplished in the select statement?Thank you in advance for any help or advice you can provide!BuckeyJane! |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
buckeyeJane
Starting Member
11 Posts |
Posted - 2011-06-16 : 12:47:34
|
| An example of the data that I would like to have is as follows:CustomerID Device Status-1 HP printer HiddenSelect customername, device, ???????? as statuswhere customername = 1 or customerid = -1Order by Device |
 |
|
|
buckeyeJane
Starting Member
11 Posts |
Posted - 2011-06-16 : 13:00:56
|
| I actually figured this out on my own.. :) I think.... I used a case statement... If there is a better way to do it, please let me know. :)CASE WHEN dbo.device.customerid < 0 THEN 'Hidden' ELSE CASE WHEN dbo.device.customerid > 0 and dbo.device.deviceid < 0 THEN 'Unmanaged' ELSE CASE WHEN dbo.device.customerid > 0 and dbo.device.deviceid > 0 THEN 'Managed' END END |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
buckeyeJane
Starting Member
11 Posts |
Posted - 2011-06-16 : 14:08:58
|
| Hi Tara - Yes. I wasn't real sure how to word that. Sorry for the confusion. I do appreciate your help and assistance... :) |
 |
|
|
|
|
|