Farooq Alsaegh Farooq Alsaegh - 1 month ago 6
ASP.NET (C#) Question

SQL Multi Condition query with Nulls Values entered in search give no results

net web app with search page I have 3 text boxes to do filtered search if I entered text in all text boxes the result will show but when I entered text in only one text box the result not showing my question is how can I to be able to search data if I entered text in only one text box or two or all of the text boxes and my query is showing below:

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)

Answer

Maybe like that:

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)
Comments