我正在尝试创建一个 INSERT SELECT 语句,该语句将数据Imported_table
从Destination_table
.
导入表
+------------------+-----------------------+
| Id (varchar(10)) | genre (varchar(4000)) |
+------------------+-----------------------+
| 6 | Comedy |
+------------------+-----------------------+
| 5 | Comedy |
+------------------+-----------------------+
| 1 | Action |
+------------------+-----------------------+
Destination_table(它应该看起来如何)
+-----------------------------+----------------------------+
| genre_name (PK,varchar(50)) | description (varchar(255)) |
+-----------------------------+----------------------------+
| Comedy | Description of Comedy |
+-----------------------------+----------------------------+
| Action | Description of Action |
+-----------------------------+----------------------------+
Imported_table.Id
根本没有使用,但仍在这个(旧)表中Destination_table.genre_name
是主键并且应该是唯一的(distinct)
Destination_table.description
编译为CONCAT('Description of ',genre)
我最好的尝试
INSERT INTO testdb.dbo.Destination_table (genre_name, description)
SELECT DISTINCT Genre,
LEFT(Genre,50) AS genre_name,
CAST(CONCAT('Description of ',Genre) AS varchar(255)) AS description
FROM MYIMDB.dbo.Imported_table
给出错误:The select list for the INSERT statement contains more items than the insert list. The number of SELECT values must match the number of INSERT columns.
提前致谢。