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.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Using Case For Dynamic Query

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2001-09-13 : 08:19:56
Derek writes "I have a query that I want to put into a stored proc, but to do this it has to be dynamic.

I will be passing it 1 variable from a web page, (let's call it @param1)

Basically, here are the three queries I wan to tie into 1 by using CASE, based on the value of @param1

1) if @param1 = 1
SELECT atable.afield
FROM atable
WHERE anotherfield = 1

2) if @param1 = 0
SELECT atable.afield
FROM atable
WHERE anotherfield = 0

3) if @param1='all'
SELECT atable.afield
FROM atable
**no where clause at all**

Thanks for any help or insight. Your site has already saved me more times than I care to count. Great job!"
   

- Advertisement -