djfeldspiff
Programmer
Hi everyone,
Below is a stored procedure referenced within a config file as part of an executable running within a SQL job. My goal is to create a DTS package and remove the dependance of the executable within the job, but I'm unsuccessful in setting the parameters to point to data the procedure process. I'll handle multiple records each time the job runs.
Can I set the parameters within the DTS package in advance of executing the stored procedure? How do I make sure I handle multiple rows of data?
Thanks so much for your direction.
Here is the stored procedure:
CREATE PROCEDURE spInsertControllerData
@AH_ALLOC_NUM as integer,
@AH_ALLOC_INV_NUM as integer,
@AL_PICK_NUM as integer,
@AH_ORD_NUM as integer,
@AL_WHS_PICK_LOC as char(7),
@PK_SHIP_METH_CD as char(1)
AS
Declare @InvNum as Integer
Declare @INVPICK as Integer
Declare @Zone as varchar (3)
Declare @Sort as integer
Declare @date as datetime
Declare @ZString as varchar(255)
Set @INVPICK = left(cast(@AH_ALLOC_INV_NUM as varchar),7 + '00') + right('00'+ cast(@AL_PICK_NUM as varchar),2)
Set @InvNum = (select invnum from tblKAdata where invnum = @INVPICK)
Set @Zone = (SELECT tblWHZONES.ZONE FROM tblWHZONES INNER JOIN tblWHLOCS ON tblWHZONES.ZNID = tblWHLOCS.ZNID WHERE (((tblWHLOCS.LOC)=substring(@AL_WHS_PICK_LOC,1,4))))
Set @Sort = (SELECT tblWHZONES.ZNSRTORD FROM tblWHZONES INNER JOIN tblWHLOCS ON tblWHZONES.ZNID = tblWHLOCS.ZNID WHERE (((tblWHLOCS.LOC)=substring(@AL_WHS_PICK_LOC,1,4))))
Set @date = getdate()
--Insert new record into tblKAdata, shipmethod (1=Air, 2=Customer Pickup, 3=International, 4=Ground, 5=USPS), date added
If isNull( @InvNum, 0) = 0 Begin
Insert Into tblKAdata values (@INVPICK, Null, CASE @PK_SHIP_METH_CD
WHEN '4' THEN '1'
WHEN '5' THEN '1'
WHEN '6' THEN '1'
WHEN 'A' THEN '1'
WHEN 'F' THEN '1'
WHEN 'N' THEN '1'
WHEN 'P' THEN '1'
WHEN 'T' THEN '1'
WHEN 'H' THEN '2'
WHEN '2' THEN '2'
WHEN 'I' THEN '3'
WHEN 'J' THEN '3'
WHEN 'K' THEN '3'
WHEN 'L' THEN '3'
WHEN 'M' THEN '3'
WHEN '7' THEN '5' else '4' END, Null, Null,@date,null,null)
End
--Insert to tblIZ Inv, Zone
Declare @Inv as integer
Set @Inv = (select inv from tblIZ where inv = @INVPICK and Zone=@Zone)
--Insert new record into tblIZ
If isNull( @Inv, 0) = 0 Begin
Insert into tblIZ values (@INVPICK, @Zone, @Sort)
-- Insert into tblIZ values (@AH_ALLOC_INV_NUM, @Zone, @Sort)
end
--select distinct zones based on Inv, order into cursor
declare zones_curs cursor for
select Zone
from tblIZ
where Inv = @INVPICK and Zone is not null
for read only
--create new variable=string of the zone data in proper order
Open zones_curs
set @Zstring=''
fetch next from zones_curs into @Zone
while @@fetch_status = 0 begin
Set @ZString = @ZString +','+ @Zone
fetch next from zones_curs into @Zone
end
close zones_curs
deallocate zones_curs
--update tblkadata.Wzone with new variable
Update tblKAdata
Set tblKAdata.WZONE = substring(@Zstring,2,254)
where tblKAdata.INVNUM = @INVPICK
GO
Below is a stored procedure referenced within a config file as part of an executable running within a SQL job. My goal is to create a DTS package and remove the dependance of the executable within the job, but I'm unsuccessful in setting the parameters to point to data the procedure process. I'll handle multiple records each time the job runs.
Can I set the parameters within the DTS package in advance of executing the stored procedure? How do I make sure I handle multiple rows of data?
Thanks so much for your direction.
Here is the stored procedure:
CREATE PROCEDURE spInsertControllerData
@AH_ALLOC_NUM as integer,
@AH_ALLOC_INV_NUM as integer,
@AL_PICK_NUM as integer,
@AH_ORD_NUM as integer,
@AL_WHS_PICK_LOC as char(7),
@PK_SHIP_METH_CD as char(1)
AS
Declare @InvNum as Integer
Declare @INVPICK as Integer
Declare @Zone as varchar (3)
Declare @Sort as integer
Declare @date as datetime
Declare @ZString as varchar(255)
Set @INVPICK = left(cast(@AH_ALLOC_INV_NUM as varchar),7 + '00') + right('00'+ cast(@AL_PICK_NUM as varchar),2)
Set @InvNum = (select invnum from tblKAdata where invnum = @INVPICK)
Set @Zone = (SELECT tblWHZONES.ZONE FROM tblWHZONES INNER JOIN tblWHLOCS ON tblWHZONES.ZNID = tblWHLOCS.ZNID WHERE (((tblWHLOCS.LOC)=substring(@AL_WHS_PICK_LOC,1,4))))
Set @Sort = (SELECT tblWHZONES.ZNSRTORD FROM tblWHZONES INNER JOIN tblWHLOCS ON tblWHZONES.ZNID = tblWHLOCS.ZNID WHERE (((tblWHLOCS.LOC)=substring(@AL_WHS_PICK_LOC,1,4))))
Set @date = getdate()
--Insert new record into tblKAdata, shipmethod (1=Air, 2=Customer Pickup, 3=International, 4=Ground, 5=USPS), date added
If isNull( @InvNum, 0) = 0 Begin
Insert Into tblKAdata values (@INVPICK, Null, CASE @PK_SHIP_METH_CD
WHEN '4' THEN '1'
WHEN '5' THEN '1'
WHEN '6' THEN '1'
WHEN 'A' THEN '1'
WHEN 'F' THEN '1'
WHEN 'N' THEN '1'
WHEN 'P' THEN '1'
WHEN 'T' THEN '1'
WHEN 'H' THEN '2'
WHEN '2' THEN '2'
WHEN 'I' THEN '3'
WHEN 'J' THEN '3'
WHEN 'K' THEN '3'
WHEN 'L' THEN '3'
WHEN 'M' THEN '3'
WHEN '7' THEN '5' else '4' END, Null, Null,@date,null,null)
End
--Insert to tblIZ Inv, Zone
Declare @Inv as integer
Set @Inv = (select inv from tblIZ where inv = @INVPICK and Zone=@Zone)
--Insert new record into tblIZ
If isNull( @Inv, 0) = 0 Begin
Insert into tblIZ values (@INVPICK, @Zone, @Sort)
-- Insert into tblIZ values (@AH_ALLOC_INV_NUM, @Zone, @Sort)
end
--select distinct zones based on Inv, order into cursor
declare zones_curs cursor for
select Zone
from tblIZ
where Inv = @INVPICK and Zone is not null
for read only
--create new variable=string of the zone data in proper order
Open zones_curs
set @Zstring=''
fetch next from zones_curs into @Zone
while @@fetch_status = 0 begin
Set @ZString = @ZString +','+ @Zone
fetch next from zones_curs into @Zone
end
close zones_curs
deallocate zones_curs
--update tblkadata.Wzone with new variable
Update tblKAdata
Set tblKAdata.WZONE = substring(@Zstring,2,254)
where tblKAdata.INVNUM = @INVPICK
GO