Here is the SP if you want. However, I would like to remind that this same SP runs smoothly and returns the correct resultset on other servers where the update is not applied.
=====CODE STARt===
CREATE procedure [dbo].[CheckInputsBeforeCalcs]
@PRODGRP INT =0,
@PERIOD INT =3,
@USERID INT =18
As
set nocount on
create table #Temptb
(
SRC INT,
SRCSAPCODE VARCHAR(10),
SOURCE VARCHAR(50),
DEST INT,
DSTSAPCODE VARCHAR(10),
DESTINATION VARCHAR(50),
VATINDICATOR VARCHAR(10),
PRODGRP INT,
MATERIAL VARCHAR(10),
MODECODE INT,
MODENAME VARCHAR(15),
DISTANCE FLOAT,
FREIGHTRATE DECIMAL(10,5),
FREIGHT DECIMAL(10,2),
DSTSTATEID INT,
SRCSTATEID INT,
SERTAXONFREIGHT DECIMAL(10,2),
TOTALFREIGHT DECIMAL(10,2),
SRCSTATE VARCHAR(25),
DESTSTATE VARCHAR(25),
SRCCO VARCHAR(50),
DSTCO VARCHAR(50)
)
IF @PRODGRP<>0
BEGIN
INSERT INTO #TEMPTB SELECT SOURCE,NULL,NULL,DESTINATION,NULL,NULL,NULL,PRODGRP,NULL,MODE,NULL,DISTANCEOVERRIDE,0,0,0,0,0,0,NULL,NULL,NULL,NULL FROM SB_LINKAGE WHERE PRODGRP=@PRODGRP AND ENABLED='TRUE'
END
ELSE
BEGIN
INSERT INTO #TEMPTB SELECT SOURCE,NULL,NULL,DESTINATION,NULL,NULL,NULL,PRODGRP,NULL,MODE,NULL,DISTANCEOVERRIDE,0,0,0,0,0,0,NULL,NULL,NULL,NULL FROM SB_LINKAGE WHERE ENABLED='TRUE'
END
UPDATE #TEMPTB SET SRCSAPCODE=(SELECT LOCCODESAP FROM SB_LOC WHERE LOCCODESB=#TEMPTB.SRC)
UPDATE #TEMPTB SET SOURCE=(SELECT LOCATION FROM SB_LOC WHERE LOCCODESB=#TEMPTB.SRC)
UPDATE #TEMPTB SET DSTSAPCODE=(SELECT LOCCODESAP FROM SB_LOC WHERE LOCCODESB=#TEMPTB.DEST)
UPDATE #TEMPTB SET DESTINATION=(SELECT LOCATION FROM SB_LOC WHERE LOCCODESB=#TEMPTB.DEST)
UPDATE #TEMPTB SET MATERIAL=(SELECT PRODGRADE FROM SB_PROD WHERE PRODGRADESBCODE=#TEMPTB.PRODGRP)
UPDATE #TEMPTB SET MODENAME=(SELECT MODEDESC FROM SB_MODE WHERE MODECODE=#TEMPTB.MODECODE)
UPDATE #TEMPTB SET DSTSTATEID=(SELECT STATE FROM SB_LOC WHERE LOCCODESB=#TEMPTB.DEST)
UPDATE #TEMPTB SET SRCSTATEID=(SELECT STATE FROM SB_LOC WHERE LOCCODESB=#TEMPTB.SRC)
UPDATE #TEMPTB SET SRCSTATE=(SELECT STATE FROM SB_STATE WHERE STATEID=#TEMPTB.SRCSTATEID)
UPDATE #TEMPTB SET DESTSTATE=(SELECT STATE FROM SB_STATE WHERE STATEID=#TEMPTB.DSTSTATEID)
UPDATE #TEMPTB SET SRCCO=(SELECT CONAME FROM SB_CO WHERE COCODE=(SELECT COCODE FROM SB_LOC WHERE LOCCODESB=#TEMPTB.SRC))
UPDATE #TEMPTB SET DSTCO='XXXX'
UPDATE #TEMPTB SET VATINDICATOR=(SELECT DESCRIPTION FROM SB_VATINDICATOR WHERE ENABLED='TRUE' AND ID=(SELECT VATINDICATOR FROM SB_TAXES WHERE STATE=#TEMPTB.DSTSTATEID AND PRODGRP=#TEMPTB.PRODGRP))
UPDATE #TEMPTB SET VATINDICATOR='CST' WHERE SRCSTATEID<>DSTSTATEID
--FRIEGHT RATE UPDATE FOR MODETYPE='R'
UPDATE #TEMPTB SET FREIGHTRATE=(SELECT RATE FROM SB_ROAD WHERE SRCLOC=#TEMPTB.SRC AND DSTLOC=#TEMPTB.DEST AND PROD=#TEMPTB.PRODGRP AND ENABLED='TRUE') WHERE MODECODE IN (SELECT MODECODE FROM SB_MODE WHERE MODETYPE='R' AND ENABLED='TRUE')
-- FREIGHT CALCULATIONS COMPLETE
alter table #temptb add LFAR decimal(10,2),RSP DECIMAL(10,2),FIXCOMM DECIMAL(10,2),VARCOMMF DECIMAL(10,2),QTVA decimal(10,2),DSP DECIMAL(10,2),ROTYPEID INT,ROTYPENAME VARCHAR(5)
UPDATE #TEMPTB SET ROTYPEID=(SELECT ROTYPE FROM SB_LOC WHERE LOCCODESB=#TEMPTB.DEST)
UPDATE #TEMPTB SET ROTYPENAME=(SELECT ROTYPENAME FROM SB_ROTYPE WHERE ROTYPEID=#TEMPTB.ROTYPEID)
UPDATE #TEMPTB SET LFAR=(SELECT LFAR FROM SB_ROWISECOMMISSION WHERE ROCODE=#TEMPTB.DEST AND MATERIALCODE=#TEMPTB.PRODGRP AND ENABLED='TRUE')
UPDATE #TEMPTB SET FIXCOMM=(SELECT FIXEDCOMMISSION FROM SB_ROWISECOMMISSION WHERE ROCODE=#TEMPTB.DEST AND MATERIALCODE=#TEMPTB.PRODGRP AND ENABLED='TRUE')
UPDATE #TEMPTB SET FIXCOMM=0 WHERE ROTYPENAME='COCO'
UPDATE #TEMPTB SET QTVA=(SELECT QRTLYTVA FROM SB_ROWISECOMMISSION WHERE ROCODE=#TEMPTB.DEST AND MATERIALCODE=#TEMPTB.PRODGRP AND ENABLED='TRUE')
UPDATE #TEMPTB SET QTVA=0 WHERE QTVA IS NULL
UPDATE #TEMPTB SET VARCOMMF=(SELECT VARCOMM FROM SB_ROWISECOMMISSION WHERE ROCODE=#TEMPTB.DEST AND MATERIALCODE=#TEMPTB.PRODGRP AND ENABLED='TRUE')
UPDATE #TEMPTB SET VARCOMMF=0 WHERE ROTYPENAME='COCO'
UPDATE #TEMPTB SET RSP=(SELECT PRICE FROM SB_PRICE WHERE LOC=#TEMPTB.DEST AND PRODUCT=#TEMPTB.PRODGRP AND PERIODID=@PERIOD AND PRICETYPE='RSP' AND ENABLED=1)
--UPDATE #TEMPTB SET RSP=0 WHERE RSP IS NULL
UPDATE #TEMPTB SET DSP=RSP-FIXCOMM+QTVA-TOTALFREIGHT WHERE RSP<>0 AND VATINDICATOR='N'
UPDATE #TEMPTB SET DSP=0 WHERE DSP IS NULL AND VATINDICATOR='N'
ALTER TABLE #TEMPTB ADD DCA_LFAR DECIMAL(10,2)
ALTER TABLE #TEMPTB ADD IRRTAXRATE DECIMAL(10,2), ED DECIMAL(10,2),PP DECIMAL(10,2),SALESTAXRATE DECIMAL(10,5),MINIMUMTAX DECIMAL(10,2),SPSALESTAX DECIMAL(10,2)
UPDATE #TEMPTB SET IRRTAXRATE=(SELECT IRRECOVERABLETAX/100 FROM SB_TAXES WHERE STATE=#TEMPTB.DSTSTATEID AND PRODGRP=#TEMPTB.PRODGRP AND IRRECOVERABLETAX IS NOT NULL)
UPDATE #TEMPTB SET ED=(SELECT (SPLADDLEXCISE+BASICCENVATFIXED+ROADINFRACESS)*1000 FROM SB_ED WHERE PRODGRP=#TEMPTB.PRODGRP)
UPDATE #TEMPTB SET PP=(SELECT PRICE FROM SB_PRICE WHERE LOC=#TEMPTB.SRC AND PRODUCT=#TEMPTB.PRODGRP AND ENABLED='TRUE' AND PERIODID=@PERIOD AND PRICETYPE='RTP')
UPDATE #TEMPTB SET SALESTAXRATE=(SELECT LSTRATE/100 FROM SB_TAXES WHERE STATE=#TEMPTB.DSTSTATEID AND PRODGRP=#TEMPTB.PRODGRP AND LSTRATE IS NOT NULL)
UPDATE #TEMPTB SET MINIMUMTAX=(SELECT MINIMUMLST FROM SB_TAXES WHERE STATE=#TEMPTB.DSTSTATEID AND PRODGRP=#TEMPTB.PRODGRP AND MINIMUMLST IS NOT NULL)
UPDATE #TEMPTB SET SPSALESTAX=(SELECT ADDLTAXONST FROM SB_TAXES WHERE STATE=#TEMPTB.DSTSTATEID AND PRODGRP=#TEMPTB.PRODGRP AND ADDLTAXONST IS NOT NULL)
SELECT DISTINCT(SRCSAPCODE),SOURCE,DSTSAPCODE,DESTINATION,MODENAME,MATERIAL,FREIGHTRATE FROM #TEMPTB where FREIGHTRATE IS NULL
SELECT DISTINCT(DSTSAPCODE),DESTINATION,MATERIAL,RSP FROM #TEMPTB WHERE RSP IS NULL
SELECT DISTINCT(SRCSAPCODE),SOURCE,MATERIAL,PP FROM #TEMPTB WHERE PP IS NULL
SELECT DISTINCT(DSTSAPCODE),DESTINATION,MATERIAL,FIXCOMM FROM #TEMPTB WHERE FIXCOMM IS NULL
SELECT DISTINCT(DSTSAPCODE),DESTINATION,MATERIAL,SALESTAXRATE FROM #TEMPTB WHERE SALESTAXRATE IS NULL
=====CODE END=====