January 19, 2007 at 5:52 am
How I can Set variable based on result of procedure
create procedure p1 as select clientname from clientmast where .....some condition
The above query returns only one record set. I would like to use the output string of procedure ie., return code of procedure p1 in the other procedure say p2 as variable for further computation. like below.....(I am very bad in coding)
create procedure p2
as
declare @myclname char(10)
set @myclname=exec p1
Thanks in advance....
January 19, 2007 at 6:03 am
This is very similar to one I answered yesterday:
http://www.sqlservercentral.com/forums/shwmessage.aspx?forumid=8&messageid=337775#bm337792
January 19, 2007 at 6:43 am
I can't change the existing procedure i.e, p1 becuse of dependencies...
Where in procedure p1 the o/p is generated by simple select statment using @variables
like
select @clclientname,@clclintid
January 19, 2007 at 7:04 am
Then I think you need to use a temp table, something like this (tweak this to suit your own requirements):
CREATE TABLE #t1 (clName char(10), clID int)
INSERT INTO #t1 EXEC p1
DECLARE @myclname char(10)
SELECT @myclname = MAX(clName)
FROM #t1
EXEC p2 @param1 = @myclname
John
January 19, 2007 at 7:42 am
Thats Excellent!!!!!
Thank you very much...
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply