replacing a value in the output result | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

replacing a value in the output result

1. I have written a simple select procedure which retrieves data from several tables using joins.
2. One of the tables has a wrong value in one of the columns.
3. While displaying data, I am supposed to display ‘NO’ instead of that value. How do I write the query? Thanks, StarWarsBigBang
If the wrong value can be found on column colX, and colX is of the VARCHAR data type, then a simple CASE construct will work: SELECT CASE WHEN colX = ‘wrong value’ THEN ‘NO’ ELSE colX END
FROM …….. If colX is a numeric data type, you need to add CAST in the CASE construct, otherwise the ‘NO’ and the colX values would clash: SELECT CASE WHEN colX = wrong_value THEN ‘NO’ ELSE CAST(colX AS VARCHAR(100)) END
FROM ……..

Thanks Adriaan, What about the other values in the inner join I am using. For example my query is like: SELECT A.studentid,A.studentname,b.age,c.department
from studentdetails A
inner join studentage B
on A.studentid=B.studentid
inner join studentdepartment C
on A.studentid=C.studentid Now the problem is that the table studentdepartment has a few entries ‘ZOOLOGY’ as a department and this needs to be shown as ‘SCIENCE’ in the output result. As per your soln I cannot do the same since I have other joins. Is there some other way to do this
Thanks, StarWarsBigBang