我有选择和过滤数据的存储过程。例如:
select CONVERT(nvarchar,[Date],120) , [FirstName] , [LastName]
FROM myDB
WHERE (@Date IS NULL OR @Date = '' OR [Date] = @Date)
(@FirstName IS NULL OR @FirstName = '' OR [FirstName] = @FirstName)
(@LastName IS NULL OR @LastName = '' OR [LastName] = @LastName)
当我通过FirstName或/和LastName进行过滤时,它可以工作,但是当我想通过Data过滤它不起作用时,我认为可能存在转换问题?我高管喜欢:
exec myProc '2013-02-03','',''
答案 0 :(得分:3)
这可能对你有所帮助 -
SELECT
CONVERT(NVARCHAR,[Date],120)
, [FirstName]
, [LastName]
FROM myDB
WHERE ISNULL(@Date, [Date]) = [Date] --<--
AND (ISNULL(@FirstName, '') = '' OR [FirstName] = @FirstName)
AND (ISNULL(@LastName, '') = '' OR [LastName] = @LastName)