I am passing table name and XML string to Sql Server SP. I want to insert records to corresponding table. how to read the column name dynamically?
Example : 1
===========
Declare @TableName = 'Table1'
Declare @xml1 xml
set @xml1 = '
insert into @TableName (
--column names from @xml
) values
(
--select ID from @xml,
--select Name from @xml
)
Example : 2
===========
Declare @TableName = 'Table2'
Declare @xml2 xml
set @xml2 = '


Manish Kumar ChoudharyRank #339 · 7.4K reputationPosted Dec 1, 2014, 8:15 PM EST
Hi Kalai,
Read these links it helps u
http://programcall.com/11/dotnet/how-to-read-data-from-xml-string--and-insert-to-table-sql-server.aspx
http://support.microsoft.com/KB/316005
KalaiRank #8,005 · 230 reputationPosted Dec 1, 2014, 8:43 PM EST
Thanks for your Reply.
Below T-SQL is working.
declare @xmlstring xml
set @xmlstring = '
SELECT
Tbl.Col.value('Id[1]', 'int') as ErrorLogID,
Tbl.Col.value('Name[1]', 'varchar(100)') as MethodName
FROM @xmlstring.nodes('/Root/Node') as Tbl(Col)
But value of @xmlstring can be vary. @xmlstring value is passed from web page. I want to read the column name dynamically.
1
Translate()
'
Sometimes it can be vary like
set @xmlstring = '