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
 General SQL Server Forums
 New to SQL Server Programming
 Changing values returned...Newbie needs help.

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 this

StaffID 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.
Go to Top of Page

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 @STAFF
SELECT 1, 50, 'In Progress' UNION ALL
SELECT 2, 20, 'On Hold' UNION ALL
SELECT 3, 30, 'Completed' UNION ALL
SELECT 4, 40, 'Completed'

SELECT
StaffId,
JobNumber,
CASE WHEN STATUS <> 'Completed' THEN 'NOT COMPLETED' ELSE 'COMPLETED' END AS STATUS
FROM
@STAFF
Go to Top of Page

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!!!
Go to Top of Page
   

- Advertisement -