for-xml-path

Replace “<” and “>” with “<” and “>” in sql server

巧了我就是萌 提交于 2019-11-30 18:52:34
Hi I am new to for xml I have a query like this SELECT ProjectId, ProjectCode, ProjectName, TechId, -- LocationId, ( SELECT GeoId,PoliticalDivisionId ,GeographicLocationName,IsoCode,Longitude,Latitude,ParentLocationId, t2.CreatedBy,t2.CreatedOn,t2.LastUpdatedBy,t2.LastUpdatedOn FROM GeographicLocation t2 WHERE GeoId = t1.LocationId FOR XML PATH('Location') ), RtoId, CreatedBy, CreatedOn, LastUpdatedBy, LastUpdatedOn FROM Project t1 where ProjectId=1 FOR XML PATH('ProjectInfo') it return the xml as <ProjectInfo> <ProjectId>1</ProjectId> <ProjectCode>US-W1-00001</ProjectCode> <ProjectName>Rees<

SQL Server : nesting elements with FOR XML PATH

自闭症网瘾萝莉.ら 提交于 2019-11-30 04:43:48
问题 I want to nest each of my XML elements. Take the following example: DECLARE @TempTable TABLE ( [Column1] char(10), [Column2] char(10) ); INSERT INTO @TempTable([Column1], [Column2]) VALUES ('some value', 'some value'), ('some value', 'some value'), ('some value', 'some value'), ('some value', 'some value') SELECT ( SELECT * FROM @TempTable FOR XML PATH('Row'), TYPE) FOR XML PATH('ParentRow'), ROOT('Root') Which will return the following XML: <Root> <ParentRow> <Row> <Column1>some value<

What is the equivalent of XML PATH and Stuff in Linq lambda expression (GROUP_CONCAT/STRING_AGG)?

半腔热情 提交于 2019-11-29 13:56:52
I am having a table like this : EmployeeId EmployeeName ItemName 4 Ganesh Key Board 4 Ganesh Processor 1 Jignesh Key Board 1 Jignesh Mouse 1 Jignesh Processor 3 Rakesh Key Board 2 Tejas Key Board 2 Tejas Mouse 2 Tejas Processor I need to query this as if the itemname is different for the same employeeid and employeename we should have the items as ',' separated. Like the one which is given below : EmployeeId EmployeeName ItemName 1 Jignesh Key Board, Mouse, Processor 2 Tejas Key Board, Mouse, Processor 3 Rakesh Key Board 4 Ganesh Key Board, Processor Here is the SQL Query for this: Could

How do I avoid character encoding when using “FOR XML PATH”?

痴心易碎 提交于 2019-11-28 04:51:18
I'm looking to create a comma-separated list of values from a SQL Server 2005 table, just like in JanetOhara's question . I'm using a query similar to the one presented in techdo's answer to the question. Everything is working, except the list of values is getting XML encoded. What should be: Sports & Recreation,x >= y Is instead returning as: Sports & Recreation,x <= y Is there a way to disable the XML character encoding when using "FOR XML" in SQL Server? Aaron Bertrand You just need to use the right options with FOR XML . Here's one approach that avoids encoding: USE tempdb; GO CREATE TABLE

What is the equivalent of XML PATH and Stuff in Linq lambda expression (GROUP_CONCAT/STRING_AGG)?

跟風遠走 提交于 2019-11-28 04:06:34
问题 I am having a table like this : EmployeeId EmployeeName ItemName 4 Ganesh Key Board 4 Ganesh Processor 1 Jignesh Key Board 1 Jignesh Mouse 1 Jignesh Processor 3 Rakesh Key Board 2 Tejas Key Board 2 Tejas Mouse 2 Tejas Processor I need to query this as if the itemname is different for the same employeeid and employeename we should have the items as ',' separated. Like the one which is given below : EmployeeId EmployeeName ItemName 1 Jignesh Key Board, Mouse, Processor 2 Tejas Key Board, Mouse,

FOR XML PATH(''): Escaping “special” characters

末鹿安然 提交于 2019-11-27 08:40:39
This code basically translates characters based on position in one string to the character at the same position in another string and it runs for all rows in the table. When I run this (simplified version): DECLARE @R char(40) DECLARE @U char(40) SET @R=' abcdefghijklmnopqrstuvwxyz!@#$%^&*()_+'+char(181) SET @U=REVERSE(@R) DECLARE @TestTable TABLE (RowID int identity(1,1) primary key, Unreadable varchar(500)) INSERT INTO @TestTable VALUES ('+µt$zw!*µsu+yt!+s$xy') INSERT INTO @TestTable VALUES ('%*!!xµpxu!(') INSERT INTO @TestTable VALUES ('pxpµnxrµu+yµs%$t') ;WITH CodeValues AS ( SELECT Number

How FOR XML PATH('') works when concatenating rows

丶灬走出姿态 提交于 2019-11-26 16:45:42
How does the FOR XML PATH ('') clause do its work when concatenating rows in SQL Server? I just want an explanation of how the FOR XML PATH ('') clause works... What FOR XML PATH('xxx') does is create an XML string for the resultset that puts each row in a <xxx></xxx> element and each column value inside the row, in an element with the name for that column. If the PATH is empty (i.e. PATH('') ) it omits the row element in the XML generation. If the column has no name it omits the column element in the XML generation. When both PATH is empty and columns have no names it effectively becomes a

How FOR XML PATH(&#39;&#39;) works when concatenating rows

谁说胖子不能爱 提交于 2019-11-26 06:03:34
问题 How does the FOR XML PATH (\'\') clause do its work when concatenating rows in SQL Server? I just want an explanation of how the FOR XML PATH (\'\') clause works... 回答1: What FOR XML PATH('xxx') does is create an XML string for the resultset that puts each row in a <xxx></xxx> element and each column value inside the row, in an element with the name for that column. If the PATH is empty (i.e. PATH('') ) it omits the row element in the XML generation. If the column has no name it omits the