Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to call a stored procedure in where clause of SQL

I have a T-SQL script, requirment is I need to call a stored procedure in where clause. This stored procedure accept a parameter and returns a bit result. Kindly guide me how to do it.

Thanks

Edit: I cant modify this sp and make it a function. please

like image 892
user576510 Avatar asked May 01 '13 06:05

user576510


2 Answers

You can not use Stored Procedure in where clause but can use User Defined Function in where clause.

If you cant convert SP to function then you have to first get bit value from executing SP and use that variable in where clause..

like image 112
Sachin Avatar answered Sep 18 '22 21:09

Sachin


You can use temporary table to store output of stored procedure and use it in where clause. The number of columns in your temporary variables must be same as that in resultset from procedure and with exact datatype as of columns in stored procedure resultset. eg,

create table #spResult ({columns as result of your sp})

insert into #spResult exec YourSP ({input parameters})

select * from yourtable 
where col in (select col from #spResult) 

drop table #spResult 
like image 24
Mudassir Hasan Avatar answered Sep 19 '22 21:09

Mudassir Hasan