列名或提供的值数与表定义错误不匹配

时间:2014-04-04 14:42:41

标签: sql select stored-procedures sql-insert

我不知道我在这里做错了什么,因为我通过选择列并插入有2列的表格,所以我不明白错误在说什么。我去了错误正在酝酿的那一行,这就是代码。

INSERT INTO #standardDefinitions1
    SELECT COLUMN_NAME as Column_Name FROM #standardDefinitions as SD
    SELECT CAST(ep.value as varchar(255)) AS Question FROM sys.extended_properties EP INNER JOIN sys.all_objects O ON ep.major_id = O.object_id INNER JOIN sys.schemas S on O.schema_id = S.schema_id INNER JOIN sys.columns AS c ON ep.major_id = c.object_id AND ep.minor_id = c.column_id
    WHERE o.name = 'Council'

CREATE TABLE #standardDefinitions1
(
    Column_Name VARCHAR(50),
    Question VARCHAR(255)
)

能让我帮忙吗?感谢。

1 个答案:

答案 0 :(得分:0)

你应该像这样加入两个选择

INSERT INTO #standardDefinitions1
SELECT SD.COLUMN_NAME as Column_Name, CAST(ep.value as varchar(255)) AS Question
FROM #standardDefinitions as SD
    INNER JOIN sys.extended_properties EP 
    INNER JOIN sys.all_objects O ON ep.major_id = O.object_id 
    INNER JOIN sys.schemas S on O.schema_id = S.schema_id 
    INNER JOIN sys.columns AS c ON ep.major_id = c.object_id AND ep.minor_id = c.column_id
WHERE o.name = 'Council'

你可以在没有条件的情况下进行完全连接,它被称为笛卡尔连接,它将表1的每一行与表2的每一行连接起来。这就是我想你应该做的。