| 
	
 | 
 Posted by Erland Sommarskog on 08/21/05 19:14 
--CELKO-- (jcelko212@earthlink.net) writes: 
>>> Is there a better to handle three parameters where any combination of  
them could be optional? << 
>  
> Let the inputs be NULL when missing and coalesce them to empty strings: 
>  
> WHERE col1 LIKE  COALESCE (@param1, '') + '%' 
>      AND  col2 LIKE  COALESCE (@param2, '') + '%' 
>      AND  col3 LIKE  COALESCE (@param3, '') + '%' 
 
I agree that NULL is better than empty strings from a conceptual point of 
view, but performance-wise it will not make things any better. 
 
 
--  
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se 
 
Books Online for SQL Server SP3 at 
http://www.microsoft.com/sql/techinfo/productdoc/2000/books.asp
 
  
Navigation:
[Reply to this message] 
 |