Here is the create statement for a 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 the database based on the values of the parameters. For example:
Select *
from dbo.test
where (LessonName = @LessonName)
AND (StartDate = @DateFrom)
AND (EndDate = @DateTo)
AND (LocationCode = @LocationCode)
Fairly simple, right? However, if any of these parameters are null (or contain an empty string), I would like to omit them from the search, and search by only the parameters that are not null. I was thinking 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.