Question : Conversion failed when converting date and/or time from character string.

This is my first official question on experts exchange, so please bear with me.  Have a "string" CSV field TRNSDATE that I am importing into SQL DB field that is "datetime" via SIS.  The below  works for a sister company (all database properties, csv properties, etc. appear identical) but give me the above "conversion failed...." error for this one company.  I'm stumped and appreciate suggestions.
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
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

Answer : Conversion failed when converting date and/or time from character string.

So, depending upon what you want to do when trnsdate contains a bad date you can either place the ISDATE in the WHERE clause to exclude the rows from being inserted, or if you want all rows inserted but convert trnsdate to null for bad dates you could use a CASE statement in the SELECT. See below for examples of both:
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 
Random Solutions  
 
programming4us programming4us