declare @s as varchar(10) = '@SOURCE@'
IF SUBSTRING(@S,1,7) = '@SOURCE' SET @s = '4'

      UPDATE [kitchen fresh foods$sales header import]
         SET [Sell-to Customer No_] = '<<ALLTRIM(lccustno)>>',
             [Document Date]        = '<<DTOC(ldordrdte)>>',
             [customer location]    = '<<ALLTRIM(lclocation)>>',
             [customer route]       = '<<ALLTRIM(lcroute)>>',
             [Document Source]      = @S,
             [production complete]  = 1,
             [open]                 = 1,
             [SBT Last Modified]    = getdate(),
             [SBT Last Modified By] = '<<THIS.cUname>>',             
             [Delivery Date]        = '<<DTOC(ld_dlvdte)>>',
             [make date]            = '<<DTOC(ld_makedte)>>',
             [make calculation]     = '<<ALLTRIM(lc_makecalc)>>',
             [make cycle]           = '<<ALLTRIM(lc_makecycle)>>',
             [delivery route]       = '<<ALLTRIM(lc_delirt)>>',
             [delivery sequence]    = <<VAL(lc_deliseq)>>,
             [Delivery Trays Qty]   = <<lnOrdrTtlTrays>>,
             [route changed]        = 0,
             [inprod change]        = 0,
             [ship customer no_]    = '<<ALLTRIM(lc_shipcust)>>',
             [ship-to code]         = '<<ALLTRIM(lc_shipto)>>',
             [label customer no_]   = '<<ALLTRIM(lc_lblcust)>>',
             [used on day]          = '<<UPPER(lcUsedOnDay)>>',
             [nav ship-to code]     = '<<ALLTRIM(lcnavshipto)>>',
             [menu cycle]           = '<<ALLTRIM(lc_menucycle)>>',
             [menu sequence no_]    = <<lc_menuseqno>>,
             [Item List Code]       = '<<ALLTRIM(lcItemListCode)>>'

         WHERE [Document No_] = '<<ALLTRIM(lcordrno)>>' and [document type] = 1

      IF @@ROWCOUNT = 0
         INSERT INTO [Kitchen Fresh Foods$sales header import]  
                     ([document type],[Document No_],[document date],[Sell-to Customer No_],
                     [customer location],[customer route],[Document Source],[nav ship-to code],
                     [production complete],[open],[Shipment Method Code],[Delivery Date],
                     [make date],[make calculation],[make cycle],[delivery route],[delivery sequence],
                     [delivery trays qty],[route changed],[inprod change],[ship customer no_],[ship-to code],
                     [label customer no_],[menu cycle],[menu sequence no_],[item list code],[used on day],
                     [SBT Last Modified],[SBT Last Modified By],[SBT Added],[SBT Added By])
             VALUES (1,'<<ALLTRIM(lcordrno)>>','<<DTOC(ldordrdte)>>','<<ALLTRIM(lccustno)>>',
                     '<<ALLTRIM(lclocation)>>','<<ALLTRIM(lcroute)>>',@S,'<<ALLTRIM(lcnavshipto)>>',
                     1,1,'999','<<DTOC(ld_dlvdte)>>',
                     '<<DTOC(ld_makedte)>>','<<ALLTRIM(lc_makecalc)>>','<<ALLTRIM(lc_makecycle)>>','<<ALLTRIM(lc_delirt)>>',<<VAL(lc_deliseq)>>,
                     0,0,0,'<<ALLTRIM(lc_shipcust)>>','<<ALLTRIM(lc_shipto)>>',
                     '<<ALLTRIM(lc_lblcust)>>','<<ALLTRIM(lc_menucycle)>>',<<lc_menuseqno>>,'<<ALLTRIM(lcItemListCode)>>','<<UPPER(lcUsedOnDay)>>',
                     GETDATE(),'<<THIS.cUname>>',GETDATE(),'<<THIS.cUname>>')
