PDA

View Full Version : [SOLVED] Excel Formula To TSQL



Marcster
08-22-2013, 10:28 AM
Hi,

Is it possible to convert an Excel formula to SQL Server Calculated Column for the below formula?:

=IF(H6=197,"Option1",IF(H6=200,"Option2",IF(H6=199,"Option3","Unknown")))

So the result would be like:

H6
Option1
Option2
Option1
Unknown

The Option1 etc does not exist on SQL Server, but field H6 does (as a number) so I manipulate the data in Excel. If the above can be done via a script that'll save me time.

Thanks

Marcster
08-26-2013, 07:57 AM
By using SQL SELECT CASE:



SELECT Field1, Field2, H6Desc =
CASE H6
WHEN 197 THEN 'Option1'
WHEN 200 THEN 'Option2'
WHEN 199 THEN 'Option3'
ELSE 'Unknown'
END
FROM Table1