1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
|
--Exclude inserting rows with bad dates
insert into partsros([invnum/ponum], partnum, partnumdesc, [tran], tc, trnsdate, qty, ucost, extcost, extsale, counterman, custnum)
select partsrostemp.[invnum/ponum],
partsrostemp.partnum,
partsrostemp.partnumdesc,
partsrostemp.[tran],
partsrostemp.tc,
convert(datetime,partsrostemp.trnsdate),
convert(money,partsrostemp.qty),
convert(money,partsrostemp.ucost),
convert(money,partsrostemp.extcost),
convert(money,partsrostemp.extsale),
partsrostemp.counterman,
partsrostemp.custnum
from partsrostemp
left outer join partsros on partsrostemp.[invnum/ponum] = partsros.[invnum/ponum]
where partsros.[invnum/ponum] is null
AND ISDATE(partsrostemp.trnsdate) = 1
--Insert all records, but NULL values for trnsdate when an invalid value is found
insert into partsros([invnum/ponum], partnum, partnumdesc, [tran], tc, trnsdate, qty, ucost, extcost, extsale, counterman, custnum)
select partsrostemp.[invnum/ponum],
partsrostemp.partnum,
partsrostemp.partnumdesc,
partsrostemp.[tran],
partsrostemp.tc,
CASE WHEN ISDATE(partsrostemp.trnsdate) = 1 THEN convert(datetime,partsrostemp.trnsdate) ELSE NULL END,
convert(money,partsrostemp.qty),
convert(money,partsrostemp.ucost),
convert(money,partsrostemp.extcost),
convert(money,partsrostemp.extsale),
partsrostemp.counterman,
partsrostemp.custnum
from partsrostemp
left outer join partsros on partsrostemp.[invnum/ponum] = partsros.[invnum/ponum]
where partsros.[invnum/ponum] is null
|