Kindly Clarify: Can we call a Stored Procedure in a SELECT statement ?

Posted by Jasminej under Sql Server on 4/26/2012 | Points: 10 | Views : 2975 | Status : [Member] | Replies : 2
Hi experts!

Can we call a Stored Procedure in a SELECT statement ?

Kindly give me a sample!

Thank You




Responses

Posted by: Pandians on: 4/26/2012 [Member] [MVP] Silver | Points: 25

Up
0
Down
YES. we can!

1.Creating a stored procedure:
Use <DatabaseName>

Go
Create Proc Proc1
(
@Parameter1 Varchar(25)
)
As
Begin
set nocount on
Select @Parameter1 [Status]
end
Go
2. Calling procedure from SELECT statement!
Use <DatabaseName>

Go
Select * from Openrowset('SQLNCLI', 'Server=<ServerName>;Trusted_Connection=yes;','Exec <DatabaseName>.dbo.Proc1 ''Dotnet Funda!''')
go
3. Result from procedure!
Status

-----------
Dotnet Funda!


Cheers
www.SQLServerbuddy.blogspot.com
iLink Multitech Solutions

Jasminej, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jasminej on: 4/26/2012 [Member] Starter | Points: 25

Up
0
Down
Wow...!

Its working. Hereafter I'll say, Yes I can call a stored procedure in a SELECT statement!

Thank You very much!


Jasminej, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response