April 18, 2007 at 10:48 am
Hi,
i need help on this. i have a stored procedure which works fine.what i want to know is to is there a way i can run the execute statement in the stored procedure before the Set Statement in the stored procedure.
CREATE PROCEDURE [dbo].[Load_Audit_Excel]
(@Return_Code int Output)
AS
BEGIN
--set @Return_Code=0
--interfering with SELECT statements.
SET NOCOUNT ON;
EXEC msdb.dbo.sp_start_job @job_name='Audit'
END
begin
set @Return_Code=(SELECT count(*) FROM [Header$])
Select @Return_Code
end
April 18, 2007 at 11:58 am
I have a question, why?
April 18, 2007 at 12:03 pm
Because i feel that its setting the values first and then executing the job .....but in my case i want to execute the job first and then check the condition and set value so how do i do that ???
April 18, 2007 at 12:04 pm
Actually, two questions, after looking closer at the procedure, are you sure it works? Looks like the set and select for Result_Code are outside the procedure to me.
April 18, 2007 at 12:06 pm
Yes but it still works
April 18, 2007 at 12:07 pm
Humor me, try this and see if it does what you want:
CREATE PROCEDURE [dbo].[Load_Audit_Excel]
(@Return_Code int Output)
AS
BEGIN
SET NOCOUNT ON;
SELECT @Return_Code = count(*) FROM [Header$]
EXEC msdb.dbo.sp_start_job @job_name='Audit'
END
thanks
April 18, 2007 at 12:19 pm
Thanks a lot, but for testing i changed the parameter as local varaible
now my proc looks like this
CREATE PROCEDURE [dbo].[Load_Audit_Excel]
AS
Declare @Return_Code int
BEGIN
SET NOCOUNT ON;
SELECT @Return_Code = count(*) FROM [Header$]
EXEC msdb.dbo.sp_start_job @job_name='Audit'
END
but when i execute the proc i want to see the value in @Return_Code but its only saying Job Started Successfully, that is the reason why i have set command used in my previous proc
wheni do set first and then do select it gives me the value in @Return_Code
Can u please help me out with this
Thanks
April 18, 2007 at 12:24 pm
No. Do the proc the way I had it. the execute statement looks something like this then (read BOL to be sure of the syntax).
declare @myvalue int
exec dbo.Load_Audi_Excel @myvalue = @Return_Code
select @myvalue -- this is the value returned from the sproc.
Viewing 8 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply