On Fri, 18 Mar 2005 06:48:42 GMT, rdraider wrote:
I'm doing a data conversion project, moving data from one SQL app to
another.
I'm using INSERT INTO with Select and have the syntax correct. But when
executing the script I get:
Server: Msg 8114, Level 16, State 5, Line 1
Error converting data type varchar to float.
Is it possible to change the data type during the INSERT INTO statement?
Hi rdraider,
If you use
INSERT INTO tablename (col1, col2, ..., colN)
SELECT expr1, expr2, ..., exprN
FROM ...
WHERE ...
Then the result of each expression will implicitly be converted to the
datatype of the corresponding column before it's stored in the table.
Your message indicates that one of your expressions is of datetype
varchar, but the corresponding column is of datatype float, and the
implicit conversion failed. E.g. because the varchar value to be
converted happened to be 'xxhasiu'.
If you use INSERT without column list, or SELECT *, then the first thing
should be to add a column list - changes to the table structure might
change the number and order of columns in the INSERT or in the SELECT *,
inducing a mismatch; explicitly naming the columns ensures that this
won't happen.
If that doesn't fix it, then find out which column(s) in the destination
table are of datatype float; run the SELECT (without the INSERT INTO) to
see the results and inspect the output to find the offending value. If
the output has too many rows for visual inspection, you might try adding
AND ISNUMERIC(exprN) = 0
This will return only the rows where exprN can't be converted to int,
float, money or decimal.
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)