Home Forums SQL Server 2008 SQL Server 2008 - General need to return all rows from any table containing a value range in a specified column RE: need to return all rows from any table containing a value range in a specified column

  • ScottPletcher (9/3/2015)


    Lynn Pettis (9/3/2015)


    ScottPletcher (9/3/2015)


    Very busy at work, just now was able to complete the code. I'll go ahead and post it as an alternative. I prefer a "template" approach, so that the overall SQL is -- to me (and maybe only me :-D) -- easier to see and change. Some like this style, some hate it, so I figured I'd give you the choice.

    ...

    I prefer to use sp_executesql where I can actually use variables and pass data into the query using appropriate data types instead of converting everything to strings to build the dynamic SQL.

    Could do that with templates as well.

    I will go with constants on these types of things because SQL will sometimes generate better plans for constant values rather than variable-based ones. I also don't see any great danger of injection here. Finally, I'd rather SQL not cache these plans, as they should be one-offs anyway, so purely ad-hoc SQL is in that sense better.

    Too many times my ad hoc's aren't.