What is a dynamic SQL query, and when would I want to use one?

Surya sasidhar picture Surya sasidhar · Feb 3, 2010 · Viewed 8.1k times · Source

What is a dynamic SQL query, and when would I want to use one? I'm using SQL Server 2005.

Answer

Kyle Rosendo picture Kyle Rosendo · Feb 3, 2010

Here's a few articles:

From Introduction to Dynamic SQL:

Dynamic SQL is a term used to mean SQL code that is generated programatically (in part or fully) by your program before it is executed. As a result it is a very flexible and powerful tool. You can use dynamic SQL to accomplish tasks such as adding where clauses to a search based on what fields are filled out on a form or to create tables with varying names.