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 2005 Forums
 Transact-SQL (2005)
 using stored proc result in conditional statement

Author  Topic 

aggiekevin
Starting Member

14 Posts

Posted - 2007-08-20 : 18:26:36
I need to use the result of a stored proc in a conditional statement.

SELECT * FROM [table_name] t
WHERE ( [sp_RecordExists] t.id )

Unfortunately, this is not possible. Is there a similar way I can accomplish this? I know my example is simple, but I have a complicated query I am performing and need to use the result of a stored proc as a condition within my WHERE clause.

Thanks!

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2007-08-20 : 19:49:44
Get the proc result into a table and query from it.

INSERT INTO #TmpResults EXEC @Proc

Dinakar Nethi
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page

pk_bohra
Master Smack Fu Yak Hacker

1182 Posts

Posted - 2007-08-21 : 01:08:31
Try with user defined function..

Can you provide more detailed explanation like.. what you are doing in the SP. What is the output SP is returning..
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-08-21 : 04:13:12
quote:
Originally posted by aggiekevin

I need to use the result of a stored proc in a conditional statement.

SELECT * FROM [table_name] t
WHERE ( [sp_RecordExists] t.id )

Unfortunately, this is not possible. Is there a similar way I can accomplish this? I know my example is simple, but I have a complicated query I am performing and need to use the result of a stored proc as a condition within my WHERE clause.

Thanks!


Create table #t(col1...........)

Insert into #t EXEC sp_RecordExists

SELECT t.* FROM [table_name] t inner join #t temp
on t.id=temp.id

Note:Avoid prefixing sp_ for user defined procedures

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -