Sunday, September 15, 2013

Compare the string, int and nText with a string in TSQL

Compare the string, int and nText data type with a string data type in  CASE WHEN TSQL

In this case, Column1 is a string, 
    
    select case when column1 = 'sometext' then 1 else 0 end
    from table1

In this case, Column1 is an integer, 

    select case when cast(column1 as varchar(max)) = 'sometext' then 1 else 0 end
    from table1

In this case, Column1 is a nText, 

    select case when cast(column1 as nvarchar(max)) = N'sometext' then 1 else 0 end
    from table1


No comments:

Post a Comment

Please include your thoughts/suggestion to make it as a better blog. If you find it useful, Please update with your valuable comments, so that others can use it.