Click here to Skip to main content
15,884,425 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I have One table "tblData" with One column "strData".

I am inserting XML string in this table.

I want to read this xml and insert record into another table.

When i write bellow code it is working fine,

C#
 Declare @xmlRec xml 
 Select TOP 1 @xmlRec = strData FROM tblData 

SELECT 
        tmpTable.col.query ('FName').value('.','varchar(50)') AS FName,
        tmpTable.col.query ('LName').value('.','varchar(50)') AS LName,
        tmpTable.col.query ('Mobile').value('.','varchar(50)') AS Mobile
FROM @xmlRec.nodes('data/data') AS tmpTable(col)


But I want to create select statement Dynamically. Like I am reading column name from another table and creating dynamic select statement.

When i execute that statement it will not work because "@xmlRec.nodes" is giving error.

I want to create dynamic Query and insert selected record into another table.

Please help....
Posted
Updated 14-May-15 2:14am
v2
Comments
Sergey Alexandrovich Kryukov 13-May-15 11:34am    
It all depends on what technology (platform, language) you use for client-side programming.
—SA
Maciej Los 13-May-15 15:48pm    
My virtual 5!
Sergey Alexandrovich Kryukov 13-May-15 16:13pm    
Thank you, Maciej.
—SA
Maciej Los 13-May-15 15:46pm    
What's error message? What line?
John C Rayan 14-May-15 8:15am    
Can you provide with the XML and related table structure?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900