Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
Hello, I am trying to figure out how to make a WHERE IF CASE. Any help will be appreciated. Thanks
SELECT * FROM vehicle WHERE CASE WHEN @make IS NOT NULL THEN VehMake LIKE @make CASE WHEN @model IS NOT NULL THEN AND VehModel LIKE @model CASE WHEN @year IS NOT NULL THEN AND Vehyr LIKE @year CASE WHEN @color IS NOT NULL THEN AND VehColor LIKE @color
this can cause bad plans to be generated and affect performance particularly for large datasets. So if performance is affected, try using dynamic sql approach------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/