Reputation: 699
I have the following SQL code:
select @colNames = coalesce(@colNames+',','')+''''+ RptLOB1 +''''
from CM.Correlation
group by RptLOB1
print @colNames
insert into AnalyticsV2.dbo.ResultCSV values('', @colNames)
and the print @colNames
gives the following:
'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 different RptLOB's.
When I execute it gives me the following error message:
Column name or number of supplied values does not match table definition.
My table has 46 columns and that blank one in the insert statement should adjust for that. Any reason as to why this would give me an error?
Any help will be appreciated!
Upvotes: 0
Views: 1397
Reputation: 70648
You are trying to insert 2 values, ''
and @colnames
on a table that has 46 columns. The fact that @colnames
is a string with values separated with commas doesn't make it as it were 45 columns, its just one string, one column.
Upvotes: 2