January 5, 2015 at 11:02 pm
-- Can anyone help me conditional based search in where clause I am getting error
Not able to post entire query please refer text file.
January 6, 2015 at 12:10 am
You forgot the END at the end (pun intended) of the CASE statement.
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP
January 6, 2015 at 2:07 am
SELECT *
FROM #parent p
LEFT OUTER JOIN #child c
ON c.CID = p.PID AND (@search = '' OR c.ChildName LIKE '%' + @search + '%')
------------------------------------------------------------------------------
SELECT *
FROM #parent p
LEFT OUTER JOIN #child c
ON c.CID = p.PID
WHERE @search = '' OR (c.CID = p.PID AND c.ChildName LIKE '%' + @search + '%')
See http://sqlinthewild.co.za/index.php/2007/11/27/parameter-sniffing/[/url] and http://sqlinthewild.co.za/index.php/2009/03/19/catch-all-queries/[/url]
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply