22,210
社区成员
发帖
与我相关
我的任务
分享
select isnull(b.id,0) as 'id',isnull(a.name,'没有结果') as '名字' from def as b
left join abc as a on a.id=b.aid
where b.id=1;
或用
select top 1
名字
from
(select name as '名字',ord=0 from a where id=0
union all
select '没有结果' as 名字,ord=1
)t
order by ord asc
可用变量传参
declare @Name nvarchar(50)
set @Name=isnull((select name as '名字' from a where id=0),'没有结果')
select @Name as 名字