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)
 conditional select statement in stored procedure

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2003-03-11 : 07:16:53
Ashok writes "I would like to use Condition in the select statement in Stored procedure
for example

create Procedure test
@EmployeeID int=0

Select * from Employee

If @EmployeeID = 0 then
No Action
else
where EmployeeID=@EmployeeID

Go

but I don't want to store it in string in @SQL and execute it..is there any solution for this.

Thanks"

Andraax
Aged Yak Warrior

790 Posts

Posted - 2003-03-11 : 07:19:34
Hi Ashok!

Try this:

select *
from Employee
where case when @EmployeeID=0 then 0 else EmployeeID end = case when @EmployeeID=0 then 0 else @EmployeeID end

Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2003-03-11 : 08:41:45
or

Select * from Employee
where EmployeeID=@EmployeeID
or @EmployeeID = 0

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -