2012-02-22 43 views
0

我有大量的數據和樣品的目的何況下面我需要wrire SP像案例與空

Create proc dbo.usp_all_property_search 
(@type varchar(2)) 
as 
begin 
select * from tbl where ol is 
select case @type 
when 'o' then null 
else 
not null 
end 

end 

PLZ幫我數據

d1 date      OL 
    N 2012-03-09 00:00:00.000  NULL 
    No 2011-09-26 00:00:00.000  OL 
    N 2012-01-26 00:00:00.000  NOL 
    N 2012-03-07 00:00:00.000  NOL 
    yes 2012-02-23 00:00:00.000  NULL 

+1

什麼是您的SP不這樣做,你需要哪些幫助? – 2012-02-22 18:10:22

+1

如果你能解釋你想要做什麼,你會找到什麼結果會有幫助嗎? – Brettski 2012-02-22 18:11:42

回答

2

你在複雜的:

SELECT * 
FROM Tbl 
WHERE (@type = 'o' AND ol IS NULL) 
OR (@Type <> 'o' AND ol IS NOT NULL) 
1
select * from tbl 
where (@type = 'o' and ol is null) OR 
    (@type <> 'o' and ol is not null) 
0

我想你想要這樣的:

select * from tbl where (@type = 'o' and ol is null) or (@type != 'o' and ol is not null) 

案例表達必須返回一個值,和SQL Server甚至不支持布爾數據類型。

0

工作的呢?

Create proc dbo.usp_all_property_search 
(@type varchar(2)) 
as 
begin 
select * from tbl 
where (@type = 'o' and ol is null) 
OR (@type != 'o' AND ol is not null) 

end 
0
Create proc dbo.usp_all_property_search(@type varchar(2)) 
as 
begin 
    select * 
    from tbl 
    where 
    (@type = 'o' and 
     ol is null)  or 
    (@type != 'o' and 
     ol is not null); 
end