OLEDB CASE WHEN in SELECT Query

VENKAT picture VENKAT · Nov 16, 2009 · Viewed 9.1k times · Source

How can use case when statement with oledb to excel file ?
Like select prodid, case prodid when 1 then 'fine' when 2 then 'good' end

Answer

mjv picture mjv · Nov 16, 2009

OLEDB is only a "relay" of sort and merely repeats the query to the underlying source.

I don't believe Excel supports the CASE WHEN construct, and thence you cannot use it, even through OLEDB.

You can instead use an Excel-specific idiom, the IIF() function, as described in CodeByMoonlight's answer. As noted the need to nest IIF() calls makes is a rather messy proposal for situations that require more than 3 or 4 cases.