I know this question has been asked and debated before. The answers I have read are mostly opinion, so I am looking for something more technical. More “under the hood”.
I’m using SQL Server 2008. I am about to write a query that will need to accept at least 11 inputs. The user could specify 1 to 11(+) of these. They are of various types (IDs, text matching, geography, full text matches, record sets, etc.). It’s as dynamic as you can get with SQL.
I know how to do this without using dynamic SQL:
/*for simple match*/ WHERE @Input IS NOT NULL OR t.col = @Input
This has drawbacks because of joins etc. I don’t ever use dynamic SQL. But from what I’ve read, it seems this may be a case for dynamic SQL.
Can anyone give some technical pointers please?
http://www.sommarskog.se/index.html
Look at the curse and blessing of Dynamic SQl and the Dynamic Search Conditions links