Monday, March 19, 2012

DECODE Statement

Is there something like the DECODE Statement in ORACLE also provided for SQL-Server?

Thanks in advance

Raimund

Look in Books On-Line for the CASE statement. You will probably want the simple CASE format. Here is an example from there:

CASE type
WHEN 'popular_comp' THEN 'Popular Computing'
WHEN 'mod_cook' THEN 'Modern Cooking'
WHEN 'business' THEN 'Business'
WHEN 'psychology' THEN 'Psychology'
WHEN 'trad_cook' THEN 'Traditional Cooking'
ELSE 'Not yet categorized'
END,

|||

You can also use it to have any expression in the WHEN section i.e.

CASE WHEN col1='Fred' THEN 'SIMON'

WHEN col2='Smith' THEN 'Jo

END

which means its very flexible. it will only process the THEN for the first WHEN that evaluates to TRUE

|||

Thanks it works fine.

Regards

Raimund

No comments:

Post a Comment