DECODE( ) function in SQL Server DECODE( ) function in SQL Server oracle oracle

DECODE( ) function in SQL Server


You could use the 'CASE .. WHEN .. THEN .. ELSE .. END' syntax in SQL.


If I understand the question correctly, you want the equivalent of decode but in T-SQL

Select YourFieldAliasName =CASE PC_SL_LDGR_CODE    WHEN '02' THEN 'DR'    ELSE 'CR'END


Just for completeness (because nobody else posted the most obvious answer):

Oracle:

DECODE(PC_SL_LDGR_CODE, '02', 'DR', 'CR')

MSSQL (2012+):

IIF(PC_SL_LDGR_CODE='02', 'DR', 'CR')

The bad news:

DECODE with more than 4 arguments would result in an ugly IIF cascade