I have a stored procedure that needs to return all pets that either have had all their vaccinations or have not had all their vaccinations.
Here is my stored procedure:
SELECT PetName, OwnerLName, OwnerFName, VaccinationDate
FROM [dbo].[myVetsOffice]
WHERE (@PetName IS NULL OR PetName LIKE '%' + @PetName + '%')
AND (@OwnerLName IS NULL OR OwnerLName LIKE '%' + @OwnerLName + '%')
AND (@OwnerFName IS NULL OR OwnerFName LIKE '%' + @OwnerFName + '%')
ORDER BY OwnerLname, OwnerFname
I have a Y/N parameter that, if it is Y, I need to add VaccinationDate IS NOT NULL else if the Y/N parameter is N, then include a clause where the VaccinationDate is null.
How do I include this in my select? I tried including a AND CASE WHEN @myparameter = 'Y' THEN VaccinationDate IS NOT NULL but that is not working. How else can I include this last bit of logic?
What I have tried:
CASE statement, google search, msdn site, blogs, stack overflow