--生成测试数据
if not object_id('Tempdb..T_20081010') is null
drop table T_20081010
Go
Create table T_20081010([ID] int,[S_ID] nvarchar(1),[P_ID] nvarchar(10))
Insert T_20081010
select 1,'a','2009-02-00' union all
select 2,'a','2009-02-28' union all
select 3,'b','2009-01-28' union all
select 4,'b','2009-01-25' union all
select 5,'b','2009-02-27' union all
select 6,'b','2009-02-26'
Go
--Select * from T_20081010
--实现:
declare @P int
set @P=''
select * from T_20081010
where (case when (id=@p) then 1 when @p='' then 1 else 0 end)=1
<style type="text/css">.csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; } </style>