To read data from xml you can use like this: Select MyXmlColumn. Value('(Record/DELETED/JID)1', 'int' ) as JID, MyXmlColumn. Value('(Record/DELETED/WID)1', 'int' ) as WID, MyXmlColumn.
Value('(Record/DELETED/AccountReference)1', 'nvarchar(255)' ) as AccountReference from table2 update create a stored procedure with your parameters: create procedure getmyxmldata ( @param1 varchar(50), @param2 varchar(50) ) as begin declare @myQuery varchar(1000); set @myQuery = 'Select MyXmlColumn. Value(''(Record/DELETED/' + @param1 + ')1'', ''nvarchar(255)'' ) as ' + @param1 + ', MyXmlColumn. Value(''(Record/DELETED/' + @param1 + ')1'', ''nvarchar(255)'' ) as ' + @param1 + ' from table2'; EXEC sp_executesql @myQuery end It is also possible to read the specified fields from the other table in this stored procedure and create your select statement dynamically without passing parameters Update 2 you can try this for multiple deleted tags: Select Row.
Value('(./JID)1', 'int' ) as JID, Row. Value('(./WID)1', 'int' ) as WID, Row. Value('(./AccountReference)1', 'nvarchar(255)' ) as AccountReference from table2 CROSS APPLY MyXmlColumn.
Nodes('/Record/DELETED') as Record(Row).
To read data from xml you can use like this: Select MyXmlColumn. Value('(Record/DELETED/JID)1', 'int' ) as JID, MyXmlColumn. Value('(Record/DELETED/WID)1', 'int' ) as WID, MyXmlColumn.
Value('(Record/DELETED/AccountReference)1', 'nvarchar(255)' ) as AccountReference from table2 update create a stored procedure with your parameters: create procedure getmyxmldata ( @param1 varchar(50), @param2 varchar(50) ) as begin declare @myQuery varchar(1000); set @myQuery = 'Select MyXmlColumn. Value(''(Record/DELETED/' + @param1 + ')1'', ''nvarchar(255)'' ) as ' + @param1 + ', MyXmlColumn. Value(''(Record/DELETED/' + @param1 + ')1'', ''nvarchar(255)'' ) as ' + @param1 + ' from table2'; EXEC sp_executesql @myQuery end It is also possible to read the specified fields from the other table in this stored procedure and create your select statement dynamically without passing parameters.
Update 2 you can try this for multiple deleted tags: Select Row. Value('(./JID)1', 'int' ) as JID, Row. Value('(./WID)1', 'int' ) as WID, Row.
Value('(./AccountReference)1', 'nvarchar(255)' ) as AccountReference from table2 CROSS APPLY MyXmlColumn. Nodes('/Record/DELETED') as Record(Row).
No I do not want to hard code the field name rather fields name are stored in another table so those field name should be fetched in sql instead of hard coded field name. How to do it. Please advise – Thomas Jun 1 at 6:36 how to query if there is more record in xml field suppose there are many means many record.
Here you specify first record MyXmlColumn. Value('(Record/DELETED/JID)1', 'int' ) as JID, you mention 1 means fetch only first record...if there are many records then how to do it. Please help – Thomas Jun 1 at 7:40 See my second update.
– ibram Jun 1 at 8:29 what is CROSS APPLY...i am not familier with CROSS APPLY. Can you please explain when CROSS APPLY is required and how it works. Thanks – Thomas Jun 1 at 18:36 Here is a good article: sqlteam.Com/article/… – ibram Jun 1 at 19:21.
I have two table in sql server 2005. In one table table1 there is one column whose data type is xml where we save data in xml format. Now I have another table table2 where we store few fileds name.
So now I want to write query in such a on xml data which will return those fields value which are defined in table2. How to achieve it with simple sql statement instead of store procedure. So please guide me how to write sql on xml data which will return only JID,WID,AccountReference,OEReference,InvoiceNumber from xml data but filed name will not be hard coded rather it will be fetch from another table table2.
Please guide me.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.