带搜索页面的网络应用程序我有3个文本框可以进行过滤搜索如果我在所有文本框中输入文本结果将显示但是当我在一个文本框中输入文本时结果没有显示我的问题是我怎么能如果我只在一个文本框或两个或所有文本框中输入文本并且我的查询显示如下,则能够搜索数据:
SELECT Emp_NUM, Full_name, Mother_Name, Date_of_Birth, Province_of_birth, Job
FROM [Emp Main Table]
WHERE (Full_name LIKE '%' + @Full_name + '%' OR Full_name IS NULL) AND
(Mother_Name LIKE '%' + @Mother_Name + '%' OR Mother_Name IS NULL) AND
(Date_of_Birth LIKE '%' + @Date_of_Birth + '%' OR Date_of_Birth IS NULL)
答案 0 :(得分:1)
使用:
rtrim(coalesce(@Full_name, '')) = ''
而不是:
@Full_name is null
用于检查空值或空值
答案 1 :(得分:0)
也许是这样的:
SELECT [Emp_NUM]
,[Full_name]
,[Mother_Name]
,[Date_of_Birth]
,[Province_of_birth]
,[Job]
FROM [Emp Main Table]
WHERE ([Full_name] LIKE '%'+@Full_name+'%' OR RTRIM(COALESCE(@Full_name,''))='')
AND ([Mother_Name] LIKE '%'+@Mother_Name+'%' OR RTRIM(COALESCE(@Mother_Name,''))='')
AND ([Date_of_Birth] LIKE '%'+@Date_of_Birth+'%' OR RTRIM(COALESCE(@Date_of_Birth,''))='')