我正在从Crystal迁移报告,我可以创建一个列并使用此公式填充...
if ({@SD Profile}="null") and ({@HD Profile 2}="null")
then ""
else
if ({@HD Profile 2}="null")
then "SD only"
else
if ({@SD Profile}="null")
then "HD only"
else
if({@SD Companion}="1")
then "HD+SD"
else "HD/SD"
我想用SQL完成同样的事情,我根据其他3列中的数据填充列的值。注意我没有在只插入报告的数据库中添加一列。
我使用
在SELECT语句中创建了空列CAST(NULL AS VARCHAR(30)) as "Content Type",
"SD_format"."name" as "SD Format",
"HD_format"."name" as "HD Format",
"destination"."sd_companion_required_flag"
基本上类似......如果SD_Format.name ='null'则Content_Type =''etc。
答案 0 :(得分:2)
您应该能够更换“如果'一个案例的陈述'语句:
select
case
when SD_Profile is null and HD_Profile is null then ''
when HD_Profile is null then 'SD only'
when SD_Profile is null then 'HD only'
when Destination = '1' then 'HD + SD'
else 'HD/SD'
end as 'Content_Type'
from ...
答案 1 :(得分:0)
*"SD_format"."name" as "SD Format",
"HD_format"."name" as "HD Format",
case
when "SD_format"."name" is null and "HD_format"."name" is null then ''
when "HD_format"."name" is null then 'SD only'
when "SD_format"."name" is null then 'HD only'
when "destination"."sd_companion_required_flag" = '1' then 'HD + SD'
else 'HD/SD'
end as "Content_Type",