Aniket Narvankar

Aniket Narvankar

  • 567
  • 2.1k
  • 604k

How to Pass parameters from one step to another step in SQL JOB

Mar 13 2023 6:52 AM

My Requirement is such that I need to do it using Job in SQL Server only. I have created a job with 7 steps. I need help in how to pass paramters from one step to another in SQL Server Job. I am giving queries of first two steps.

1.Here is query of step 1

declare @lastRunStatus nvarchar(4)
declare @bkp nvarchar(10)
declare @bky nvarchar(10)
declare @bkpd varchar(10)
declare @bkyr varchar(10)
declare @bkpbky varchar(6)

select @lastRunStatus = LastRunStatus,@bkp = BookingPeriod,@bky = BookingYear 
from tbl1 where Roll_Forward_Type_Name='AY_Allocation'     
    
select @bkpd = Cast(BookingPeriod as varchar(10)),@bkyr = Cast(BookingYear as varchar(10)) from  tbl2 where DomainCode='PSTIBR' and closedFlag='N'

@bkpd,@bky,@bkpbky,@bkp,@bkyr

I want to pass this parameters from step 1 to step 2.

2.Here is the query of step 2

Select * from tbl_Allocation_Status_Test where bky=@bky and bkp=@bkp and bkpbky=@bkpbky and bkyr=@bkyr and bkpd=@bkpd

There are total 7 steps in job and in that steps also I need to pass parameters from one step to another. Please help me understanding on how to pass parameters from one step to another. I need to go with sql job as per company's requirement and limitations.


Answers (2)