Here is the create statement for the stored procedure:
Create Procedure SearchCreatedAssignments
(@LessonName Varchar(50), @DateFrom date, @DateTo Date, @LocationCode Varchar(10))
As
BEGIN
Basically, I want to write a query that searches for a database based on parameter values. For instance:
Select *
from dbo.test
where (LessonName = @LessonName)
AND (StartDate = @DateFrom)
AND (EndDate = @DateTo)
AND (LocationCode = @LocationCode)
Pretty simple, right? However, if any of these parameters is null (or contains an empty string), I would like to omit them from the search and search only for parameters that are not equal to zero. I thought something like this:
--if @LocationCode is null OR @LocationCode = '' -> omit @LocationCode from the search
This is obviously pseudo code. How can i do this? Forgive me if this is a simple task; I am new to SQL.
source
share