您的位置:程序门 -> ms-sql server -> 基础类



一个查询中的字查询,请问怎么在子查询返回空行时显示我指定的字符


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


一个查询中的字查询,请问怎么在子查询返回空行时显示我指定的字符[已结贴,结贴人:wjjdnajj]
发表于:2007-01-20 16:43:41 楼主

形如:
(select   csid   from   approve_currentstep   where   ceid=approve_stable.eid   and   cpassed=0))   as   '有记录 ' "

如果子查询返回空行时怎么让这个值显示我指定的字符,比如“无字符”?
发表于:2007-01-20 16:46:241楼 得分:0
case     呗
发表于:2007-01-20 16:47:302楼 得分:0
--try

if   exists(select   csid   from   approve_currentstep   where   ceid=approve_stable.eid   and   cpassed=0)
print   '有记录 '
else  
print   '无字符 '
发表于:2007-01-20 16:47:583楼 得分:0
用exists判断吧
发表于:2007-01-20 16:49:074楼 得分:0
isnull((select   csid   from   approve_currentstep   where   ceid=approve_stable.eid   and   cpassed=0)   as   '有记录 ', '無記錄 ')
发表于:2007-01-20 16:53:505楼 得分:0
搞錯國,很不好意思
发表于:2007-01-20 17:08:136楼 得分:0
select   isnull(csid, '无字符 ')   from   approve_currentstep   where   ceid=approve_stable.eid   and   cpassed=0
发表于:2007-01-20 17:35:287楼 得分:0
我的意思是如果符合条件的记录存在就显示符合条件的记录,如果没有符合条件的记录则显示自己指定的字符。

如果用case,能不能这样写:

case(exists(select   csid   from   approve_currentstep   where   ceid=approve_stable.eid   and   cpassed=0))  
when   true   then   (select   csid   from   approve_currentstep   where   ceid=approve_stable.eid   and   cpassed=0)  
when   false   then   '无记录 '
end
发表于:2007-01-22 09:36:418楼 得分:0
意思应该很清楚了啊,怎么没人理啊?
发表于:2007-01-22 09:47:009楼 得分:10
--try

case   when   exists(select   1   from   approve_currentstep   where   ceid=approve_stable.eid   and   cpassed=0)
then
(select   rtrim(csid)   from   approve_currentstep   where   ceid=approve_stable.eid   and   cpassed=0)
else   '无记录 '
end
发表于:2007-01-22 10:13:2510楼 得分:10
要不是这样
select   case   isnull(csid, ' ')   when   ' '   then   '无记录 '   else   csid   from   approve_currentstep   where   ceid=approve_stable.eid   and   cpassed=0


快速检索

最新资讯
热门点击