for-xml

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

若如初见. 提交于 2019-12-30 06:02:09
问题 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

CTE and FOR XML to generate nested XML

谁说胖子不能爱 提交于 2019-12-29 05:21:34
问题 I have an adjacency list in the DB and want to deliver the data in XML format to the client through a SQL SP. I'm trying to use CTE and FOR XML but I am not getting the XML nodes to nest. FYI, this will represent a site map. The Table structure: CREATE TABLE [dbo].[PageHierarchy]( [ModuleId] [int] NOT NULL, [PageId] [int] IDENTITY(1,1) NOT NULL, [ParentPageId] [int] NULL, [PageUrl] [nvarchar](100) NULL, [PageTitle] [nvarchar](50) NOT NULL, [PageOrder] [int] NULL) and the beginnings of the CTE

t-sql most efficient row to column? crosstab for xml path, pivot

烂漫一生 提交于 2019-12-24 16:32:31
问题 I am looking for the most performant way to turn rows into columns. I have a requirement to output the contents of the db (not actual schema below, but concept is similar) in both fixed width and delimited formats. The below FOR XML PATH query gives me the result I want, but when dealing with anything other than small amounts of data, can take awhile. select orderid ,REPLACE(( SELECT ' ' + CAST(ProductId as varchar) FROM _details d WHERE d.OrderId = o.OrderId ORDER BY d.OrderId,d.DetailId FOR

Trouble with Namespaces in T-SQL FOR XML queries

谁都会走 提交于 2019-12-24 03:10:22
问题 I have a question about using SQL Server FOR XML to create XML documents with namespaces. I need to create a document like below where there is a namespace definition in the root element ( xmlns:ijk="h:/i.j.k" ), and a namespace reference in a child element attribute ( ijk:LMNO="3333" ). I am generating the XML to POST to a Web service: <ROOT xmlns:ijk="h:/i.j.k" RSTU="1111"> <CHILD CDEF="2222" ijk:LMNO="3333" /> </ROOT> I wrote this first sample query to get the structure correct before I

SQL Server 2005 For XML Explicit - Need help formatting

我是研究僧i 提交于 2019-12-23 07:15:31
问题 I have a table with a structure like the following: ------------------------------ LocationID | AccountNumber ------------------------------ long-guid-here | 12345 long-guid-here | 54321 To pass into another stored procedure, I need the XML to look like this: <root> <clientID>12345</clientID> <clientID>54321</clientID> </root> The best I've been able to do so far was getting it like this: <root clientID="10705"/> I'm using this SQL statement: SELECT 1 as tag, null as parent, AccountNumber as

How to break up two xml tags with the same subchild names in SQL

﹥>﹥吖頭↗ 提交于 2019-12-22 17:42:18
问题 I have created a script which takes data from a table in SQL and generates an XML output. The parent, child and sub-child tags are all the same which for 2 tags. The SQL script is outputting them as one XML value instead of 2. SELECT Request.TransactionRef AS [RequestHeader/RequestID], 'Deal.Trial' AS [RequestHeader/Action], 'DoDealValidate' AS [RequestHeader/ActionFlags/Flag], 'DoDealDerive' AS [RequestHeader/ActionFlags/Flag] The current results are: <ActionFlags> <Flag

Query to get XML output for hierarchical data using FOR XML PATH in SQL Server

倖福魔咒の 提交于 2019-12-21 03:58:06
问题 I have a table with columns NodeId, NodeName, ParentNodeId and I want to ouput entire table data in the form of Xml like the following using SQL query. I think FOR XML PATH mode in Sql server can be used to achieve this (I use SQL Server 2008) using recursion, but not sure how. Thanks in advance <?xml version="1.0" encoding="utf-8" ?> <Nodes> <Node Id="1" Name="node1"> <Node Id="11" Name="node11"> <Node Id="111" Name="node111" /> <Node Id="112" Name="node112" /> </Node> </Node> <Node Id="2"

FOR XML SQL Server - Variable Element name in output XML

放肆的年华 提交于 2019-12-13 14:17:12
问题 I'm quite new to FOR XML in SQL Server, I've searched considerable and I can't find an answer to this. Can I have a variable element name using 'for xml' where the element name is not hard-coded and is instead take from a cell in each row? Take the following example... Table ORDERS : ID STATUS TIME AMOUNT ------------------------------------ 1 COMPLETE 02:31 2355 2 ACCEPTED 02:39 6653 3 ACCEPTED 04:21 4102 4 RECEIVED 05:03 4225 FOR XML query: select ID, TIME as STATUS_TIME, AMOUNT as CURRENT

Embedding a sql case statement into a sql query that is using FOR XML

安稳与你 提交于 2019-12-13 07:43:17
问题 I received some wonderful assistance from a fellow SO user yesterday (see here ) which allowed me to make a great deal of progress towards my goal. Now I'm attempting to establish whether the magical addition that was suggested can be embedded into an existing query that is producing xml output. The existing query is as follows: PROCEDURE [dbo].[CreateLandingPurchaseOrderDetails] -- Add the parameters for the stored procedure here @startDate DATE, @endDate DATE AS BEGIN -- SET NOCOUNT ON

SQL FOR XML multilevel from one pivoted table

送分小仙女□ 提交于 2019-12-13 02:12:43
问题 I've been trying to use FOR XML without success to do the following. Source table: Country | ID | 1950 | 1955 ----------------------------------------------------- Country 1 | 1 | 2.43 | 2.55 Country 2 | 2 | 4.54 | 42.15 Desired output: <locations> <location> <loc name='Country 1' id='1' /> <dub> <data year='1950' value='2.43' /> <data year='1955' value='2.55' /> </dub> </location> <location> <loc name='Country 2' id='2' /> <dub> <data year='1950' value='4.54' /> <data year='1955' value='42