select top 1 (Speak_add_time) from Speaks
where Speak_Theme_id = 9
order by Speak_add_time desc
如果 Speak_add_time 这个字段为空 就执行
select Speak_add_time from Theme
用变量的我也会,你给的也不对,我想1条语句判断出来
不用变量的
楼主,我想弄清一个问题:
如果Speak_add_time为空就查出Theme表中所有数据?还是查出Theme表中Speak_Theme_id=9的那个Speak_add_time?
如果是后面这种情况的话,可以尝试以下sql语句:
select case when Speak_add_time is null then (select Speak_add_time from Theme where Speak_Theme_id = 9) else (top 1 (Speak_add_time)) end
from Speaks
where Speak_Theme_id = 9
order by Speak_add_time desc
如果Speak_add_time为空就查出Theme表中所有数据?还是查出Theme表中Speak_Theme_id=9的那个Speak_add_time?
如果是后面这种情况的话,可以尝试以下sql语句:
select case when Speak_add_time is null then (select Speak_add_time from Theme where Speak_Theme_id = 9) else (top 1 (Speak_add_time)) end
from Speaks
where Speak_Theme_id = 9
order by Speak_add_time desc
温馨提示:答案为网友推荐,仅供参考
第1个回答 2008-03-11
declare @time 类型
@time=select top 1 (Speak_add_time) from Speaks
where Speak_Theme_id = 9
if(@time=为空)
select top 1 (Speak_add_time) from Speaks
where Speak_Theme_id = 9
@time=select top 1 (Speak_add_time) from Speaks
where Speak_Theme_id = 9
if(@time=为空)
select top 1 (Speak_add_time) from Speaks
where Speak_Theme_id = 9