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.
| Author |
Topic |
|
savvy
Starting Member
48 Posts |
Posted - 2007-03-24 : 07:59:31
|
| Can I use a Stored Procedure value in a Select Statement.For Example:Lets Say sp_SelectSortIDreturns only one integer value which is 2442So, when I do 'EXEC sp_SelectSortID' it gives SortID2442But if I want to use this in Select statement, For Eg: I want something like " Select * from Credits Where SortID= (Exec sp_SelectSortID)is it actually possible ? This question was asked to me in my interview yesterday. I searched in google but didn't get relevant results. Any ideas will be of great help to me Thanks in AdvanceSavvy |
|
|
bpgupta
Yak Posting Veteran
75 Posts |
Posted - 2007-03-24 : 08:49:50
|
| U can't use the Stored Proc in the Select statement.to use the same things..u assigne to out of SP to one variable then use that variable in the select statement.Thanks,Bali |
 |
|
|
jezemine
Master Smack Fu Yak Hacker
2886 Posts |
Posted - 2007-03-24 : 11:05:45
|
have a look at OUTPUT params in procs in BOL. www.elsasoft.org |
 |
|
|
savvy
Starting Member
48 Posts |
Posted - 2007-03-24 : 15:05:45
|
| wow! Thank you very much guys for your answersI done a little bit of research and came out with a working example which works on my table Example: ***************CREATE PROCEDURE sp_Temp(@creditID int,@sortID int OUTPUT) ASSelect @sortID=SortID from SelectedCredits where CreditID=@creditIDGO****************DECLARE @TempSortID intExec sp_Temp @creditID=111, @sortID=@TempSortID OUTPUTSelect TheCount = @TempSortID*************I am giving this example if incase someone else is searching for the same This will be bit helpful for them Thank you very very much guys for your help Savvy |
 |
|
|
|
|
|