I have table eRx (store electronic prescription) which has a pharmacy column. I am passing two optional parameters for pharmacy.
I declared the parameters like this:
DECLARE @pharmacy varchar(50) = null,
@Pharmacy1 varchar(50) = null
and use them in the where clause
WHERE (eRx.Pharmacy LIKE '%' + @Pharmacy + '%'
OR @Pharmacy IS NULL
OR eRx.Pharmacy LIKE '%' + @Pharmacy1 + '%'
OR @Pharmacy1 IS NULL)
If I am passing only one parameter, I am getting all records. It is not working as expected.
For example, if I will pass @pharmacy = 'CVS', I am getting all the rows. If I will pass both the parameter, then result is returned as expected.
Please help me