rammi
rammi

Reputation: 81

How to change query from SQL Server 2012 to SQL Server 2008 R2

SELECT 
    @Principal= IIF(optionfieldvalue='', NULL, CAST(optionfieldvalue as decimal(38, 18)))
FROM 
    @DATA 
WHERE 
    TemplateFieldId = 47

This query was written in SQL Server 2012. Now I want to change that to SQL Server 2008 R2.

can any one help who to convert that code

Upvotes: 0

Views: 26

Answers (1)

marc_s
marc_s

Reputation: 755013

Just get rid of the IIF which is new in SQL Server 2012:

SELECT 
    @Principal = CASE 
                   WHEN optionfieldvalue = '' 
                      THEN CAST(NULL AS DECIMAL(38,18))
                      ELSE CAST(optionfieldvalue AS DECIMAL(38, 18))
                 END
FROM 
    @DATA 
WHERE 
    TemplateFieldId = 47

Upvotes: 1

Related Questions