Conditional statements in SQL query

Conditional statements in SQL query

Post by dslab » Thu, 06 Mar 2003 00:36:30



I have a stored procedure that I pass a parameter with
null default. I would like to build a SQL query based on
the values of the parameters I pass. How would I use a
conditional statement to write the query without repeating
the whole query string for each condition?

If there is a sample somewhere, please reference it.

 
 
 

Conditional statements in SQL query

Post by Bob Barrow » Thu, 06 Mar 2003 00:44:34


http://www.algonet.se/~sommar/dynamic_sql.html

Bob Barrows

Quote:> I have a stored procedure that I pass a parameter with
> null default. I would like to build a SQL query based on
> the values of the parameters I pass. How would I use a
> conditional statement to write the query without repeating
> the whole query string for each condition?

> If there is a sample somewhere, please reference it.


 
 
 

Conditional statements in SQL query

Post by Aaron Bertrand [MVP » Thu, 06 Mar 2003 01:03:57


http://www.aspfaq.com/2348

--
Aaron Bertrand, SQL Server MVP
http://www.aspfaq.com/

Please reply in the newsgroups, but if you absolutely
must reply via e-mail, please take out the TRASH.


Quote:> I have a stored procedure that I pass a parameter with
> null default. I would like to build a SQL query based on
> the values of the parameters I pass. How would I use a
> conditional statement to write the query without repeating
> the whole query string for each condition?

> If there is a sample somewhere, please reference it.