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
 SQL Server Development (2000)
 TSQL

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2001-04-23 : 16:56:19
Shahzad writes "Hello GURU
I've to use SQL statement in stored procedure, which is dynamic in its where clause. The SP should be like that

Create Proc[myProc]
Declare @a int
As
Select DocumentID
From tblDocument
Where 0=0
if @a = NULL and DocumentID=@a

and so on it goes for multiple values in form which we pass as variable in our SP.
I hope you understand what I want to do. It is to search for the fields, which user has entered in form. If not entered display result for whole table. But it gives an error on IF statement that we cant use IF in where. We can solve this problem by using ASP to write query becuase then we use its if statement. But I want to make a SP of this whole process.

Thanks a lot in advance if you solve this problem or give an alternative."
   

- Advertisement -