August 3, 2016 at 2:47 am
Hi Experts,
How can i run my stored procedure inside select statement?
example:
Select Username, exec @myproc from userinfo
Regards,
Mizan
August 3, 2016 at 2:58 am
You can't do it like that, for two reasons. First, you can't use a variable to represent the name of the stored procedure. If you don't know at design time which stored procedure you'll be running then you'll need to use dynamic SQL. Suppose you do know which stored procedure you need, though - you now need to insert the result set of the stored procedure into a table (or table variable) and then join to that in your query. Have a go at that, and post back if there's anything you don't understand. Stored procedure and table definitions and sample data (in the form of INSERT statements) will help if you require more detailed assistance.
John
August 3, 2016 at 3:16 am
mizan700 (8/3/2016)
Hi Experts,How can i run my stored procedure inside select statement?
example:
Select Username, exec @myproc from userinfo
Regards,
Mizan
Can't you add UserName to the output of the stored procedure?
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
August 3, 2016 at 4:37 am
strictly this usage is not possible in SQL Server as the other expert suggested.
For better help, you need to post the associated DDL and DML statements with sample data.
Thanks,
Durga Prasad
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply