如果存储过程中的语句

时间:2014-05-08 18:01:50

标签: sql-server-2008 tsql

我正在尝试创建一个存储过程,该过程将根据" deletedbyuser"显示所有或仅显示当前项目。列。

ALTER PROCEDURE [dbo].[usp_FWPF]
    -- Add the parameters for the stored procedure here
    @userLabs varchar(max),
    @showall char(1) = 'N'
AS
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    --SET NOCOUNT ON;

select dat.* from brFWPFileR br
full outer join  datFWPFileS  dat
on br.FileS_ID=dat.FileS_ID
where (br.Lab_ID in =@userLabs or dat.UploadedByLab_ID=@userLabs)
and
if @showall = 'N' 
dat.DeletedyByUserID is NULL
else
dat.DeletedyByUserID = dat.DeletedyByUserID
end if



END

但是我在''''''''''''

;'

我使用case when语句尝试了同样的操作,但它仍无效。

1 个答案:

答案 0 :(得分:0)

这将为您提供所需的内容

select dat.* from brFWPFileR br
full outer join  datFWPFileS  dat
on br.FileS_ID=dat.FileS_ID
where (br.Lab_ID in =@userLabs or dat.UploadedByLab_ID=@userLabs)
and
(
(@showall = 'N' AND dat.DeletedyByUserID is NULL)
OR
(@showall = 'Y' AND dat.DeletedyByUserID = dat.DeletedyByUserID)
)

@ Showall =“X”之后的实际标准可能会根据您在@Showall变量的每个条件下查找的结果而有所不同。