'Convert SQL Server IIF function to Redshift
I have sql server script, that I need to convert to Redshift
Here is part of code that I have problem with
IIF(smf.channelid IS NULL, 0, 1) AS IsFeatureKey,
IIF(codeLabel.CslId > 0, 1, 0) AS IsCslCode,
IIF(codeLabel.LearnId > 0, 1, 0) AS IsLearnCode,
IIF(codeLabel.PMId > 0, 1, 0) AS IsPMCode,
IIF(codeLabel.UpSell > 0, 1, 0) AS IsUpSell
How I can convert it to Redshift correctly?
Solution 1:[1]
IIF is just syntactic sugar for CASE expression (this behavior is mentioned in the documentation). Your code is identical to:
CASE WHEN smf.channelid IS NULL THEN 0 ELSE 1 END AS IsFeatureKey,
CASE WHEN codeLabel.CslId > 0 THEN 1 ELSE 0 END AS IsCslCode,
CASE WHEN codeLabel.LearnId > 0 THEN 1 ELSE 0 END AS IsLearnCode,
CASE WHEN codeLabel.PMId > 0 THEN 1 ELSE 0 END AS IsPMCode,
CASE WHEN codeLabel.UpSell > 0 THEN 1 ELSE 0 END AS IsUpSell
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
