I am trying to use SELECT INTO
and UNION ALL
to join 3 tables together.
Table 1 uses a number of Ltrim(Rtrim())
and CONVERT
commands, whilst with the other two tables, I am just taking their columns out and pasting them into this combined table.
When I try to run the query, I get an error message saying:
Conversion failed when converting date and/or time from character string.
but dealing with the tables individually, everything runs smoothly.
What is the cause of this, and how do I fix it?
EDIT: Here is a sample of the union of the first two tables;
SELECT
, CONVERT(DATE, [GL DATE], 101) AS [Date1]
, CONVERT(FLOAT, [Amount_01]) AS [Amt]
INTO #big_table
FROM table1
UNION ALL
[POSDATE] AS [Date1]
, [NET] AS [Amt] NULL AS [Date_Up]
, NULL AS [Time_up]
,
FROM table2
Edit #2:
I have located the trouble columns, they are [Date1] and [Amt].
For table 1, here is sample data from both these columns:
Date1 Amt
4/28/2014 216.43
4/28/2014 1526.61
4/28/2014 13.61
4/27/2014 177.9
4/27/2014 489.58
For table 2:
Date1 Amt
30/04/2014 -7501.9
30/04/2014 0
30/03/2014 -75201.9
30/03/2014 0
28/02/2014 -25247.93
28/02/2014 0
For Table 3:
Date1 Amt
21/04/2014 100,000,000.00
21/04/2014 -2,312,314.44
21/04/2014 -100,000,000.00
21/04/2014 56.41
26/04/2014 2,312,314.44
26/04/2014 -125.4
If I am not mistaken, there is a problem with the format of Date1
in tables 2 and 3 compared to table 1, since the 2 and 3 are : DD/MM/YYYY
, whereas table 1 is MM/DD/YYYY
.
But why isn't Amt
working? can non-positive numbers not be converted to float?
How would I address this issue and make a working conversion?
edit 3: For table 3:
I tried using CONVERT(DATE,[Date1],103) and it worked, but the same strategy fails for table 2, despite having the same input/output structure - what could be the reason for this?
I again receive:
Conversion failed when converting date and/or time from character string.