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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Converting one string to another in a T-SQL Query

Author  Topic 

yahazim
Starting Member

13 Posts

Posted - 2002-05-14 : 16:00:23
I have multiple FLAG fields that use SMALLINT datatype with either "-1" or "0" as the possible inputted data.

I have numerous stored procedures that return the results of those FLAG fields. However I want the user of the database to be able to read those results as something more meaningful than "-1" or "0".

I want to return the "-1" as YES and the "0" as NO.

How can I convert this in the stored procedure using T-SQL instead of joining the table to another?

Thank you in advance.

Jim

robvolk
Most Valuable Yak

15732 Posts

Posted - 2002-05-14 : 16:07:39
SELECT CASE Flag1
WHEN -1 THEN 'Yes'
WHEN 0 THEN 'No'
END
FROM FlagTable


If you are certain that only -1 and 0 are in those columns, then this will work too:

SELECT CASE Flag1
WHEN -1 THEN 'Yes'
ELSE 'No'
END
FROM FlagTable


Considering that a smallint is two bytes, and if you don't need anything other than yes or no, why not just convert the column to a varchar(3) and actually store "yes" or "no"? Or, make it a char(1) column with "Y" or "N" values...you'd save space AND eliminate the need to do the conversion.

Go to Top of Page

yahazim
Starting Member

13 Posts

Posted - 2002-05-14 : 20:45:38
THANK YOU.]

Go to Top of Page
   

- Advertisement -