Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
evanburen
Posting Yak Master
167 Posts |
Posted - 2005-02-11 : 15:43:44
|
| I'm using this code from an article on this site to create a dynamic WHERE clause for an ASP page. CREATE PROCEDURE sp_DynamicSQL(@Ticker nvarchar(255) = NULL,@CompanyName nvarchar(255) = NULL,@Industry nvarchar(255) =NULL)ASSELECT Ticker, CompanyName, IndustryFROM TCompaniesWHERE Ticker = COALESCE(@Ticker,Ticker) ANDCompanyName = COALESCE(@CompanyName, CompanyName) ANDIndustry = COALESCE(@Industry,Industry)GOI need to search the @CompanyName variable like using LIKE '%@CompanyName%' but I don't know how to do this using COALESCE. Something like this:CompanyName = LIKE COALESCE(%@CompanyName%, CompanyName) ANDThanks. |
|
|
Seventhnight
Master Smack Fu Yak Hacker
2878 Posts |
Posted - 2005-02-11 : 16:47:19
|
I would do it more like:where(Ticker = @Ticker or @ticker is null)and (CompanyName like '%'+@companyName+'%' or @companyName is null)and(Industry = @Industry or @Industry is null)Corey "If the only tool you have is a hammer, the whole world looks like a nail." - Mark Twain |
 |
|
|
|
|
|