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 |
|
bobg
Starting Member
2 Posts |
Posted - 2008-05-29 : 22:43:50
|
| Hi Guys,I have had a look through the forum and I can't seem to be able to find how to do this... I have a vague recollection of achieving this before but it was many years ago since I've done any sql.I have a table like thisStaffID JobNumber Status------- --------- ------1 50 'In Progress'2 20 'On Hold'3 30 'Completed'4 40 'Completed'what I want to be able to do is change the status to something common if it is not 'Completed' I don't want to update the database though, I just want to return it in a select statement. Is this possible. My output would be something like;StaffID JobNumber Status------- --------- ------1 50 'NOT Completed'2 20 'NOT Completed'3 30 'Completed'4 40 'Completed'Many thanks in Advance.Bobg |
|
|
sodeep
Master Smack Fu Yak Hacker
7174 Posts |
Posted - 2008-05-29 : 23:09:05
|
| With Case statement. |
 |
|
|
raky
Aged Yak Warrior
767 Posts |
Posted - 2008-05-29 : 23:55:55
|
| DECLARE @STAFF TABLE ( StaffId INT, JobNumber INT, Status VARCHAR(16))INSERT INTO @STAFFSELECT 1, 50, 'In Progress' UNION ALLSELECT 2, 20, 'On Hold' UNION ALLSELECT 3, 30, 'Completed' UNION ALLSELECT 4, 40, 'Completed'SELECT StaffId, JobNumber, CASE WHEN STATUS <> 'Completed' THEN 'NOT COMPLETED' ELSE 'COMPLETED' END AS STATUSFROM @STAFF |
 |
|
|
bobg
Starting Member
2 Posts |
Posted - 2008-05-30 : 02:07:56
|
| thanks guys... I got it working with a case statement as suggested...Thanks!!! |
 |
|
|
|
|
|
|
|