Larry Brister
asked on
Complex SQL Server WHERE CLause
In my where statement below...
I need to include this logic...
Where @FIlter = 'BOOKING'
... add "AND criminal.Ignore=0"
I need to include this logic...
Where @FIlter = 'BOOKING'
... add "AND criminal.Ignore=0"
WHERE ISNULL(i.isDeleted, 0) = ISNULL(@isDeleted, 0)
AND s.SalesSiteID = ISNULL(@SalesSiteID, s.SalesSiteID)
AND i.IndividualTypeID = 2
AND (
(i.LastName LIKE '%' + ISNULL(@SearchOther, i.LastName) + '%')
OR (i.FirstName LIKE '%' + ISNULL(@SearchOther, i.FirstName) + '%')
OR (i.EmployeeID LIKE '%' + ISNULL(@SearchOther, i.EmployeeID) + '%'
OR ee.EmailAddress = @SearchOther)
)
AND criminal.jsondata LIKE '%' + ISNULL(@filter,criminal.jsondata) + '%'
Is there any trick on your question?
If not then it should be simple as:
If not then it should be simple as:
WHERE ISNULL(i.isDeleted, 0) = ISNULL(@isDeleted, 0)
AND s.SalesSiteID = ISNULL(@SalesSiteID, s.SalesSiteID)
AND i.IndividualTypeID = 2
AND (
(i.LastName LIKE '%' + ISNULL(@SearchOther, i.LastName) + '%')
OR (i.FirstName LIKE '%' + ISNULL(@SearchOther, i.FirstName) + '%')
OR (i.EmployeeID LIKE '%' + ISNULL(@SearchOther, i.EmployeeID) + '%'
OR ee.EmailAddress = @SearchOther)
)
AND criminal.jsondata LIKE '%' + ISNULL(@filter,criminal.jsondata) + '%'
AND @FIlter = 'BOOKING'
AND criminal.Ignore=0
ASKER
Neither of those work.
I will be passing in either NULL or 'BOOKING' in @filter
SO the [AND] statement has to be included only If criminal.jsondata contains 'BOOKING' AND criminal.Ignore = 0
ELSe
No FIlter
I will be passing in either NULL or 'BOOKING' in @filter
SO the [AND] statement has to be included only If criminal.jsondata contains 'BOOKING' AND criminal.Ignore = 0
ELSe
No FIlter
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Jim Horn
Fair enough
You've helped me for years and have earned the right of a "correction" in methodology.
That said...
Yours as well as Vitors both worked in context of the way I framed the question.
Vitors actually gave me the final solution with "best expert guess."
I will be splitting the points if you guys don't mind
Fair enough
You've helped me for years and have earned the right of a "correction" in methodology.
That said...
Yours as well as Vitors both worked in context of the way I framed the question.
Vitors actually gave me the final solution with "best expert guess."
I will be splitting the points if you guys don't mind
I'm ok with the split.
Cheers
Cheers
ASKER
Thanks guys
Have a blessed day
Have a blessed day
Thanks for the split, and thanks for understanding. -Jim
Open in new window