USE Database
GO
CREATE PROCEDURE FillTable
@Id nvarchar(50),
@ColumnNameArray nvarchar(4000),
@ColumnValueArray nvarchar(4000)
AS
INSERT INTO Table(@ColumnNameArray)
VALUES (@ColumnValueArray)
GO
This is the functionality i require in my stored procedure. But i get the error as
Invalid column name '@zoneNameArray'.
So whats the work around?
How can I make this work?
EDIT 1:
I tried using it like this as said by SO users.
select @sql_Str='
INSERT INTO Table('+@ColumnNameArray+')
VALUES ('+@ColumnValueArray+')'
But i still have error. The ColumnNameArray goes well. But wen it comes to ColumnValueArray i still cant get it right.
ColumnValueArray consists of both strings and int.
eg: ColumnValueArray = "12,'abc','dddd',45,'2333'" this is what i pass from my front end (C#) to the stored procedure parameter.
please try this
Assuming @ColumnNameArray is a comma separated list of columns