-1

So I've got these two tables that I'm trying to copy data between and according to http://msdn.microsoft.com/en-us/library/ms187928.aspx I shouldn't have a problem doing the conversion but it seems that I do. Here are the two tables with the pertinent information for diagnosing this issue:

Table1
col1(PK, int, not null)
col2(varchar(4608), null)
col3(datetime, null)
col4(datetime, null)
col5(char(12), null)
col6(datetime, null)
col7(int, null)
col8(datetime, null)
col9(char(1), not null)
col10(varchar(25), null)
col11(char(1), null)
col12(char(1), null)
col13(char(1), null)
col14(uniqueidentifier, null)
col15(FK, in, null)

Table2
col1(PK, int, not null)
col2(varchar(4608), null)
col3(datetime, null)
col4(datetime, null)
col5(char(12), null)
col6(datetime, null)
col7(int, null)
col8(varchar(80), null)
col9(varchar(120), null)
col10(datetime, null)
col11(char(1), not null)
col12(varchar(25), null)
col13(char(1), null)
col14(char(1), null)
col15(char(1), null)

Now this is the where the odd business comes into play. Columns 14 and 15 in Table1 correspond to Columns 8 and 9 in Table 2. Other than that, you can clearly see which columns line up according to their data types right? So the code for copying those odd columns is here: (Assume that this is at the bottom of...

SET IDENTITY_INSERT Table2 ON;
DELETE FROM Table2;
INSERT INTO Table2 (
col1, col2, col3, col4, col5, col6, col7, col8, col9, col10, col11, col12, col13, col14, col15)
SELECT col1, col2, col3, col4, col5, col6, col7, col8, col9, col10, col11, col12, col13
,CAST(col14 AS VARCHAR(80))
,CAST(col15 AS VARCHAR(120))
FROM Table1;
SET IDENTITY_INSERT Table2 OFF;

And this is the error message I get:

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

What's happening here?

4

1 回答 1

0

在您的查询col10中(按我的继续)在列列表和select语句中的相同位置。

varchar在表 2 中的表anddatetime` 中。

这可能是您的问题所在。

于 2013-04-26T14:15:47.270 回答