Subject | SQL Truncation & error issue |
---|---|
Author | Ryan Nilsson-Harding |
Post date | 2004-04-14T01:13:49Z |
Hi there,
I'm not understanding what's going on with a particular error I'm
receiving from a union'ed query, and was hoping I could glean some
sensibilities from this group.
I'm performing a select query on 4 tables.
3 of the tables contain a VARCHAR(12) field 'BOXNUM' and the fourth
has a VARCHAR(64) field 'BOXDESC' which I am trying to
CAST as a VARCHAR(12) AS BOXNUM with little success.
SELECT BOXNUM FROM TBLA
UNION
SELECT BOXNUM FROM TBLB
UNION
SELECT BOXNUM FROM TBLC
UNION
SELECT CAST(BOXDESC AS VARCHAR(12)) AS BOXNUM
There is no problem if the datum in BOXDESC is 12 chars or less.
If there is more however, I was under the impression that this would
truncate whatever datum was in the BOXDESC field down to 12 chars, but
this is obviously incorrect.
Instead (if the datum has more than 12 characters) I am getting the error
335544321 (arithmetic exception, numeric overflow or string truncation).
Which is then followed by an endless amount of 335544569 (Cursor
unknown) errors.
Say the field has 15 chars, and I cast it to VARCHAR(15), the query
works fine on that table alone. But when I use the unioned query I now
receive a 335544569 (Data Type unknown)
Could somone please make these errors make sense?
I figured the data type WOULD be known because I'm telling it (CAST
... VARCHAR(x))
Is there a convenient way to carry out this truncation on this one
table's field alone?
Rgds,
-Ryan
I'm not understanding what's going on with a particular error I'm
receiving from a union'ed query, and was hoping I could glean some
sensibilities from this group.
I'm performing a select query on 4 tables.
3 of the tables contain a VARCHAR(12) field 'BOXNUM' and the fourth
has a VARCHAR(64) field 'BOXDESC' which I am trying to
CAST as a VARCHAR(12) AS BOXNUM with little success.
SELECT BOXNUM FROM TBLA
UNION
SELECT BOXNUM FROM TBLB
UNION
SELECT BOXNUM FROM TBLC
UNION
SELECT CAST(BOXDESC AS VARCHAR(12)) AS BOXNUM
There is no problem if the datum in BOXDESC is 12 chars or less.
If there is more however, I was under the impression that this would
truncate whatever datum was in the BOXDESC field down to 12 chars, but
this is obviously incorrect.
Instead (if the datum has more than 12 characters) I am getting the error
335544321 (arithmetic exception, numeric overflow or string truncation).
Which is then followed by an endless amount of 335544569 (Cursor
unknown) errors.
Say the field has 15 chars, and I cast it to VARCHAR(15), the query
works fine on that table alone. But when I use the unioned query I now
receive a 335544569 (Data Type unknown)
Could somone please make these errors make sense?
I figured the data type WOULD be known because I'm telling it (CAST
... VARCHAR(x))
Is there a convenient way to carry out this truncation on this one
table's field alone?
Rgds,
-Ryan