View Single Post

   
  #2 (permalink)  
Old 02-28-2008, 07:42 PM
--CELKO--
 
Posts: n/a
Default Re: conditional logic in stored procedure

>> I would only like to execute the LIKE conditions only when the
variable in question is not NULL. I did a test and if the variable is
set to null, obviously the select does not return what I'm expecting.
<<

SELECT *
FROM Foobar
WHERE kbtitle LIKE COALESCE(@ins1, kbtitle)
AND ikbtitle LIKE COALESCE(@ins2, ikbtitle)
AND ikbtitle NOT LIKE COALESCE(@ins3, '')
AND ikbbody LIKE COALESCE(@ins1, ikbbody)
AND ikbbody LIKE COALESCE(@ins2, ikbbody)
AND ikbbody NOT LIKE COALESCE(@ins3,'')
Reply With Quote