I have this insert, first of all it doesnt work, maybe I need a Join statement, But is there an easier way to write this, cause it will not work, any help would be appreciated.
Thanks in advance
Insert into [dbo].[tblArTransHeader] (
TransId,
TransType,
BatchId,
CustId,
ShipToName,
ShipToAddr1,
ShipToAddr2,
ShipToCity,
ShipToRegion,
ShipToPostalCode,
TermsCode,
TaxableYN,
InvcNum,
InvcDate,
Rep1Id,
Rep1Pct,
GLPeriod,
FiscalYear,
TaxGrpID,
NonTaxSubtotal,
DistCode,
CurrencyID,
SumHistPeriod
)
Select Arecvid,
'1',
'######',
SubscriberNumber,
[Name],
addr1,
addr2,
city,
state,
zip,
terms,
taxable,
NINVC,
InvoiceDate,
slsrep1,
rep1pct,
[MO],
YR,
taxloc,
Debit,
distcode,
currency,
[MO]
from TST.dbo.ACMARVIEW1
if TST.dbo.ACMARVIEW1.flatrate <> 0
Insert into dbo.tblArTransDetail (
TransID,
EntryNum,
PartId,
[Desc],
AddnlDesc,
TaxClass,
GLAcctSales,
GLAcctCOGS,
GLAcctInv,
QtyOrdSell,
UnitsSell,
QtyShipSell,
UnitPriceSell
)
Select Arecvid,
'1',
'MONTHLYFEE',
'Transaction Fee',
left (FlatRateCharge,12),
'0',
'5001001',
'4001001',
'5001001',
NumFlatRate,
'EACH',
NumFlatRate,
FlatRate
from TST.dbo.ACMARVIEW1
if TST.dbo.ACMARVIEW1.rate <> 0
Insert into dbo.tblArTransDetail (
TransID,
EntryNum,
PartId,
[Desc],
TaxClass,
GLAcctSales,
GLAcctCOGS,
GLAcctInv,
QtyOrdSell,
UnitsSell,
QtyShipSell,
UnitPriceSell
)
Select Arecvid,
'2',
'MONTHLYFEE',
'Percentage Fee',
'0',
'5001001',
'4001001',
'5001001',
RateCharge,
'EACH',
RateCharge,
Rate
from TST.dbo.ACMARVIEW1
if TST.dbo.ACMARVIEW1.maximusrate <> 0
Insert into dbo.tblArTransDetail (
TransID,
EntryNum,
PartId,
[Desc],
TaxClass,
GLAcctSales,
GLAcctCOGS,
GLAcctInv,
QtyOrdSell,
UnitsSell,
QtyShipSell,
UnitPriceSell
)
Select Arecvid,
'3',
'MAXFEE',
'Maximum Fee',
'0',
'5001001',
'4001001',
'5001001',
'1',
'EACH',
'1',
MaximusRate
from TST.dbo.ACMARVIEW1
if TST.dbo.ACMARVIEW1.delinquencycharge <> 0
Insert into dbo.tblArTransDetail (
TransID,
EntryNum,
PartId,
[Desc],
TaxClass,
GLAcctSales,
GLAcctCOGS,
GLAcctInv,
QtyOrdSell,
UnitsSell,
QtyShipSell,
UnitPriceSell
)
Select Arecvid,
'4',
'DELFEE',
'Delinquency Charge',
'0',
'5001001',
'4001001',
'5001001',
'1',
'EACH',
'1',
delinquencyCharge
from TST.dbo.ACMARVIEW1
Thanks in advance
Insert into [dbo].[tblArTransHeader] (
TransId,
TransType,
BatchId,
CustId,
ShipToName,
ShipToAddr1,
ShipToAddr2,
ShipToCity,
ShipToRegion,
ShipToPostalCode,
TermsCode,
TaxableYN,
InvcNum,
InvcDate,
Rep1Id,
Rep1Pct,
GLPeriod,
FiscalYear,
TaxGrpID,
NonTaxSubtotal,
DistCode,
CurrencyID,
SumHistPeriod
)
Select Arecvid,
'1',
'######',
SubscriberNumber,
[Name],
addr1,
addr2,
city,
state,
zip,
terms,
taxable,
NINVC,
InvoiceDate,
slsrep1,
rep1pct,
[MO],
YR,
taxloc,
Debit,
distcode,
currency,
[MO]
from TST.dbo.ACMARVIEW1
if TST.dbo.ACMARVIEW1.flatrate <> 0
Insert into dbo.tblArTransDetail (
TransID,
EntryNum,
PartId,
[Desc],
AddnlDesc,
TaxClass,
GLAcctSales,
GLAcctCOGS,
GLAcctInv,
QtyOrdSell,
UnitsSell,
QtyShipSell,
UnitPriceSell
)
Select Arecvid,
'1',
'MONTHLYFEE',
'Transaction Fee',
left (FlatRateCharge,12),
'0',
'5001001',
'4001001',
'5001001',
NumFlatRate,
'EACH',
NumFlatRate,
FlatRate
from TST.dbo.ACMARVIEW1
if TST.dbo.ACMARVIEW1.rate <> 0
Insert into dbo.tblArTransDetail (
TransID,
EntryNum,
PartId,
[Desc],
TaxClass,
GLAcctSales,
GLAcctCOGS,
GLAcctInv,
QtyOrdSell,
UnitsSell,
QtyShipSell,
UnitPriceSell
)
Select Arecvid,
'2',
'MONTHLYFEE',
'Percentage Fee',
'0',
'5001001',
'4001001',
'5001001',
RateCharge,
'EACH',
RateCharge,
Rate
from TST.dbo.ACMARVIEW1
if TST.dbo.ACMARVIEW1.maximusrate <> 0
Insert into dbo.tblArTransDetail (
TransID,
EntryNum,
PartId,
[Desc],
TaxClass,
GLAcctSales,
GLAcctCOGS,
GLAcctInv,
QtyOrdSell,
UnitsSell,
QtyShipSell,
UnitPriceSell
)
Select Arecvid,
'3',
'MAXFEE',
'Maximum Fee',
'0',
'5001001',
'4001001',
'5001001',
'1',
'EACH',
'1',
MaximusRate
from TST.dbo.ACMARVIEW1
if TST.dbo.ACMARVIEW1.delinquencycharge <> 0
Insert into dbo.tblArTransDetail (
TransID,
EntryNum,
PartId,
[Desc],
TaxClass,
GLAcctSales,
GLAcctCOGS,
GLAcctInv,
QtyOrdSell,
UnitsSell,
QtyShipSell,
UnitPriceSell
)
Select Arecvid,
'4',
'DELFEE',
'Delinquency Charge',
'0',
'5001001',
'4001001',
'5001001',
'1',
'EACH',
'1',
delinquencyCharge
from TST.dbo.ACMARVIEW1