for-xml-path

SQL Server : Group by string concatenation

喜你入骨 提交于 2019-12-09 01:26:35
问题 I have a question. I know that has been asked before. I looked through the related questions but I could not get my SQL script to work. Here is my query : SELECT T1.PART_ID, T2.ID, T2.DESCRIPTION FROM #TEMP T1 INNER JOIN #TEMP2 T2 ON T1.PART_ID = T2.PART_ID ORDER BY T2.ID Table: PART_ID | ID | DESCRIPTION ---------------------------------- 10002 | 1182505 | Tagfahrlichtschaltung 80029 | 1182505 | Bluetooth 20004 | 1212866 | Kindersitzbefestigung 10045 | 1212866 | Lederlenkradrriegelung 11908

Parse <img> tag that lies within the <description></description> of an rss2 feed item

…衆ロ難τιáo~ 提交于 2019-12-08 08:50:54
问题 What I try to accomplish is get the src attribute of an RSS2 feed item using GDataXML . The feed's item xml is like this: <item> <title>BlackBerry EMEA servers crash</title> <link>http://www.mysite.com/?p=672</link> <comments>http://www.mysite.com/?p=672#comments</comments> <pubDate>Mon, 10 Oct 2011 21:11:24 +0000</pubDate> <dc:creator>acreator</dc:creator> <category><![CDATA[Latest News]]></category> <description><![CDATA[<span class="image-rss"><a href="http://www.mysite.com/?p=672"><img

Default namespace with FOR XML PATH

有些话、适合烂在心里 提交于 2019-12-08 02:44:50
问题 Consider the following SQL: ;WITH XMLNAMESPACES(DEFAULT 'http://www.mynamespace.co.uk') ,CTE_DummyData AS ( select id=1 ) select TOP 1 [@ID]=1, (select top 1 [@ID] = 1 FROM CTE_DummyData FOR XML PATH ('Child'), TYPE) from CTE_DummyData FOR XML PATH ('Parent') Thie returns the xml: <Parent xmlns="http://www.mynamespace.co.uk" ID="1"> <Child xmlns="http://www.mynamespace.co.uk" ID="1" /> </Parent> What I need is to return the xml with the xmlns declaration on only the root element. eg: <Parent

Comma Delimited Result set + SQL Query

只愿长相守 提交于 2019-12-08 02:05:08
问题 I got two tables with data as listed below: Table1: Student Table2: Subject I need the output as: I got this acheived with below query using for XML PATH Code: WITH cte AS ( SELECT Stu.Student_Id , Stu.Student_Name , ( SELECT Sub.[Subject] + ',' FROM [Subject] AS Sub WHERE Sub.Student_Id = Stu.Student_Id ORDER BY Sub.[Subject] FOR XML PATH('') ) AS [Subjects] FROM dbo.Student AS Stu ) SELECT Student_id [Student Id] , student_name [Student Name] , SUBSTRING(Subjects, 1, ( LEN(Subjects) - 1 ))

Default namespace with FOR XML PATH

好久不见. 提交于 2019-12-06 10:04:18
Consider the following SQL: ;WITH XMLNAMESPACES(DEFAULT 'http://www.mynamespace.co.uk') ,CTE_DummyData AS ( select id=1 ) select TOP 1 [@ID]=1, (select top 1 [@ID] = 1 FROM CTE_DummyData FOR XML PATH ('Child'), TYPE) from CTE_DummyData FOR XML PATH ('Parent') Thie returns the xml: <Parent xmlns="http://www.mynamespace.co.uk" ID="1"> <Child xmlns="http://www.mynamespace.co.uk" ID="1" /> </Parent> What I need is to return the xml with the xmlns declaration on only the root element. eg: <Parent xmlns="http://www.mynamespace.co.uk" ID="1"> <Child ID="1" /> </Parent> Is there a way to do this? Note

Comma Delimited Result set + SQL Query

北战南征 提交于 2019-12-06 04:47:59
I got two tables with data as listed below: Table1: Student Table2: Subject I need the output as: I got this acheived with below query using for XML PATH Code: WITH cte AS ( SELECT Stu.Student_Id , Stu.Student_Name , ( SELECT Sub.[Subject] + ',' FROM [Subject] AS Sub WHERE Sub.Student_Id = Stu.Student_Id ORDER BY Sub.[Subject] FOR XML PATH('') ) AS [Subjects] FROM dbo.Student AS Stu ) SELECT Student_id [Student Id] , student_name [Student Name] , SUBSTRING(Subjects, 1, ( LEN(Subjects) - 1 )) AS [Student Subjects] FROM cte My question is there a better way to do this without using XML Path?

Storing the text of a stored procedure in an XML data type in SQL Server

百般思念 提交于 2019-12-03 18:13:18
问题 I need to store the text of all of the stored procedures in a database into an XML data type. When I use, FOR XML PATH , the text within in the stored procedure contains serialized data characters like and for CRLF and " , etc. I need the text to stored in the xml structure without these characters because the text will need to be used to recreate the stored procedure. This is the query that I use for FOR XML PATH : SELECT [View].name AS "@VName", [Module].definition AS "@VDefinition"

Eliminate row in XML based on criteria

ぃ、小莉子 提交于 2019-12-02 01:11:13
here's the script to create the needed data: CREATE TABLE [dbo].[TestXML]( [ID] [int] NOT NULL, [PID] [int] NULL, [Code] [int] NULL, [Col1] [int] NULL, [Col2] [int] NULL, [Col3] [decimal](6, 2) NULL, [Col4] [decimal](6, 2) NULL, [Col5] [int] NULL, CONSTRAINT [PK_TestXML] PRIMARY KEY CLUSTERED ([ID] ASC) ) GO CREATE TABLE [dbo].[XML_Columns_Reference]( [TableName] nvarchar(10) NULL, [TableNameXML] nvarchar(10) NULL, [ColumnName] nvarchar(10) NULL, [ColumnNameXML] nvarchar(10) NULL, [ColumnOrder] [int] NULL, [GroupName] nvarchar(10) NULL, [GroupOrder] [int] NULL, [Category] [int] NULL ) ON

Concatenation of strings by for xml path

折月煮酒 提交于 2019-12-01 08:22:02
Hi! Today I learned for xml path technique to concatenate strings in mssql. Since I've never worked with xml in mssql and google hasn't helped, I need to ask you. Let's imagine the default case. We need to concatenate some strings from a table: declare @xmlRepNames xml = ( select ', [' + report_name + ']' from ( select distinct report_order, report_name from #report ) x order by report_order for xml path(''), type) select stuff((select @xmlRepNames.value('.', 'nvarchar(max)')), 1, 1, '') So I get smth like this: [str1], [str2], [strn] Ok. It works fine. But I have two very similar concatenate

SQL Server : Group by string concatenation

独自空忆成欢 提交于 2019-12-01 00:53:00
I have a question. I know that has been asked before. I looked through the related questions but I could not get my SQL script to work. Here is my query : SELECT T1.PART_ID, T2.ID, T2.DESCRIPTION FROM #TEMP T1 INNER JOIN #TEMP2 T2 ON T1.PART_ID = T2.PART_ID ORDER BY T2.ID Table: PART_ID | ID | DESCRIPTION ---------------------------------- 10002 | 1182505 | Tagfahrlichtschaltung 80029 | 1182505 | Bluetooth 20004 | 1212866 | Kindersitzbefestigung 10045 | 1212866 | Lederlenkradrriegelung 11908 | 1257946 | Airbag 22346 | 1257946 | Automatic I want have the result like: ID | LISTOFPARTS ----------