DECLARE @ONum int --variable
DECLARE @CrUsId nvarchar(128) = 'D901D15C-62FA-4243-A3DB-D3D448DC3F91'--assign value
DECLARE @From Datetime = 4/2/2017 --assign value
DECLARE @To Datetime = 25/2/2017 --assign value
`declare @day nvarchar(50)`
`select * from PurchaseOrder`
where
CreateUserID = CASE @CrUsId
WHEN @CrUsId = '' THEN CreateUserID
WHEN @CrUsId <> CreateUserID THEN NULL -- if input is some text but
WHEN @CrUsId IS NULL THEN CreateUserID
WHEN @CrUsId != '' AND CreateUserID = @CrUsId THEN CreateUserID
END
答案 0 :(得分:0)
这是你想要做的吗?
select * from PurchaseOrder
where CreateUserID =
CASE
WHEN @CrUsId = '' OR @CrUsId IS NULL THEN CreateUserID
WHEN @CrUsId <> CreateUserID THEN NULL -- if input is some text but
WHEN @CrUsId = CreateUserID THEN CreateUserID
END