select Where id=? 时显示空值
比如有一SQL语句:select * from jc_Paper where id in (1,2,3,4)
查询结果为:
而我想要的结果是这样的
请问各位位,SQL语句应该怎么写?谢谢!
[解决办法]
大概这样,其他字段我不写了
----------------------------------------------------------------
-- Author :DBA_Huangzj(發糞塗牆)
-- Date :2014-01-02 13:03:13
-- Version:
-- Microsoft SQL Server 2012 (SP1) - 11.0.3128.0 (X64)
--Dec 28 2012 20:23:12
--Copyright (c) Microsoft Corporation
--Enterprise Edition (64-bit) on Windows NT 6.2 <X64> (Build 9200: )
--
----------------------------------------------------------------
--> 测试数据:[jc_Paper]
if object_id('[jc_Paper]') is not null drop table [jc_Paper]
go
create table [jc_Paper]([id] int,[subjectid] varchar(4),[unitid] int)
insert [jc_Paper]
select 1,'A001',1 union all
select 3,'A001',1 union all
select 4,'A001',1
--------------开始查询--------------------------
select ISNULL(a.id,b.id)id,a.subjectid,a.unitid
from [jc_Paper] a full join (select 1 id union all select 2 union all select 3 union all select 4) as b on a.id=b.id
ORDER BY id
----------------结果----------------------------
/*
id subjectid unitid
----------- --------- -----------
1 A001 1
2 NULL NULL
3 A001 1
4 A001 1
*/
select a.id,b.*
from (select 1 id union all select 2 union all select 3 union all select 4) a
left join jc_pager b
on a.id=b.id
and b.id in (1,2,3,4)