我试图添加到现有的SQL查询以输出" No Data Found"如果整个查询为null。
我想显示"没有找到数据"而不是显示空白输出。
数据库我正在编写SQL查询是针对InterSystems Cache的。任何帮助是极大的赞赏。
这是我正在使用
的查询SELECT Case
when sn.1_code = 1 then 'Attended -- ' ||
sn.mult_1 ||
'and' ||
sn.dict_2 ||
' also acted with ' ||
sn.dict_3 ||
'.'
when sn.1_code = 3 then 'left because ' ||
sn.mult_2 ||
'.'
when sn.dict_1 = 2 then 'Went home'
when sn.dict_1 = 24 then 'Canceled' END AS 'Attendance',
sn.dict_2 AS 'Continue'
FROM db.sn
Where sn.dict_2 = 123
如果查询是基于where子句的,那么输出应显示文本"今天没有找到123的数据"而不是在我的系统上显示空白屏幕的内容。如果不是isnull那么将显示数据。
IF Query isnull output should show
NO DATA FOUND FOR 123 TODAY
If Query not isnull output should show
Attendance: Continue:
Attended today. Also Acted with respect Great
Left because not feeling well Excussed
Went Home Not Excused
由于
答案 0 :(得分:1)
CASE
围绕IsNull
:
SELECT
IsNull(
CASE
when sn.1_code = 1
then 'Attended -- ' ||
sn.mult_1 ||
'and' ||
sn.dict_2 ||
' also acted with ' ||
sn.dict_3 ||
'.'
when sn.1_code = 3
then 'left because ' ||
sn.mult_2 ||
'.'
when sn.dict_1 = 2
then 'Went home'
when sn.dict_1 = 24
then 'Canceled'
END , 'No Data Found' ) AS 'Attendance'
FROM db.sn