22,209
社区成员
发帖
与我相关
我的任务
分享
declare @tb table(id int,score int)
insert @tb
select 1, 60
union
select 2, 50
select a.number id,ISNULL(b.score,0 )score from (select * from master..spt_values where type='p' and number>0)a left join @tb b on a.number=b.id
where a.number=3
create table table1(id int, score int)
insert into table1
select 1, 60 union all
select 2, 50
declare @id int
select @id=3
select @id 'id',
isnull((select score
from table1
where id=@id),0) 'score'
/*
id score
----------- -----------
3 0
(1 row(s) affected)
*/
declare @id int
select @id=1
select @id 'id',
isnull((select score
from table1
where id=@id),0) 'score'
/*
id score
----------- -----------
1 60
(1 row(s) affected)
*/