FAQ Database Discussion Community


SQL XML Parsing in T-SQL

sql,sql-server,sql-server-2012,sqlxml
I have SQL Server table which has XML column that has data like below. Multiple records will be there in the table. Let us say table T1 and Column C1. Our requirement is we need to get the latest data (by max of datereported, datecreated, dateupdated XML node for individual...

How to use local-name(.) within dynamic sql statement

sql-server,stored-procedures,dynamic-sql,sqlxml,sql-function
I have the following code to create a SQL function that will parse an XML string and create a table of key value pairs that represent the nodes and values. This works fine for me in my use cases. CREATE FUNCTION XmlToKeyValue ( @rootName AS varchar(256), @xml AS Xml )...

Update XML data type without creating duplicate nodes

sql-server,tsql,sql-server-2012,sqlxml
In my application, users can select groups of skills to search, which are stored as XML. In this simple example, I have the following structure in a table with a primary XML index included. CREATE TABLE #myTable (ID int IDENTITY(1,1) PRIMARY KEY, userId int NOT NULL, searchXml xml not null);...

SQL Server - convert XML Column to delimited string

sql,sql-server,sqlxml
Gurus, I have XML Column value like below in SQL 2012 '<XMLDoc> <AAA> <Name>Name_A</Name> <Value>Val_A</Value> </AAA> <AAA> <Name>Name_B</Name> <Value>Val_B</Value> </AAA> <AAA> <Name>Name_C</Name> <Value>Val_C</Value> </AAA> <AAA> <Name>Name_D</Name> <Value>Val_D</Value> </AAA> <AAA> <Name>Name_E</Name> <Value>Val_E</Value> </AAA> : :...

Query XML data in SQL Server using replace in criteria

sql-server,sqlxml
I have an XML column in my SQL Server 2008 table. What I'm trying to do is for a given parameter to my stored procedure strip out any spaces (using REPLACE) in the param and use this in the WHERE criteria but then using the XQuery exist clause also use...

Problems With FOR XML AUTO

sql,asp.net,sql-server,subquery,sqlxml
i have the following Query: SELECT QuestionID_PK , QuestionTitle , ( SELECT dbo.Tags.TagID_PK , dbo.Tags.TagTitle , dbo.Tags.TagTitle_EN FROM dbo.Question_Tag_Rel INNER JOIN dbo.Questions ON dbo.Question_Tag_Rel.QuestionID_FK = dbo.Questions.QuestionID_PK INNER JOIN dbo.Tags ON dbo.Question_Tag_Rel.TagID_FK = dbo.Tags.TagID_PK AND dbo.Questions.QuestionID_PK = '2116' FOR XML PATH('') , TYPE , ELEMENTS ) AS Tags FROM Questions WHERE...

SQL : Find if XML node exists

sql,sql-server,tsql,sqlxml
Assuming I have a table data as below: I want to Select all Value(XML Data) which contains the node Name="Hello World". How can I achieve it? SQL Fiddle set @f = @XML.exist('/ArrayOfFilterColumn/SelectColumn[(@Name) eq "Hello World"]'); select @f; I am not sure how could I add it in my where condition,...