0

我有以下 SQL 代码:

select @colNames = coalesce(@colNames+',','')+''''+ RptLOB1 +''''
from CM.Correlation
group by RptLOB1

print @colNames

insert into AnalyticsV2.dbo.ResultCSV values('', @colNames)

打印@colNames内容如下:

'Accident and Health','AE','Avemco Aviation','Bail','Commercial','Contingency','Contract','Court','Credit','DFP','DIC','Disability','Energy and Marine','EPLI','Excess Casualty','Exited Lines','Fidelis Marine','Fidelity','Group Life','HC Houston Aviation','HCC Indemnity Guaranty','HCCG International','HCCG US','HCCMIS','HCRM','Indemco','Large Commercial','Liability','Medical Stop Loss','MPL','Niche and Other Specialty','Occupational Accident','Other Aviation','Other International','Other Surety','Other US PC','PI','Primary Casualty','Property DF','Property Treaty','Public Risk','Surety','Technical Property','UK Credit','USSIC Aviation'

45 个不同的 RptLOB。

当我执行它给我以下错误信息:

列名或提供的值的数量与表定义不匹配。

我的表有 46 列,插入语句中的空白列应该对此进行调整。为什么这会给我一个错误?

任何帮助将不胜感激!

4

1 回答 1

2

您正在尝试在具有 46 列的表上''插入2 个值。@colnames事实上,它@colnames是一个值用逗号分隔的字符串,并没有使它成为 45 列,它只是一个字符串,一列。

于 2012-10-01T20:23:33.667 回答