for-xml-explicit

SQL Server FOR XML - Basic query

大兔子大兔子 提交于 2019-12-24 00:58:12
问题 I have been given an XML document that I want to generate via a SQL script, I've not done something like this and haven't been able to find any examples that can lead me to being able to generate the final XML I need (and I'm not sure which of the possible methods available if one is better suited to what I need - EXPLICIT or PATH or if its even possible). I'm hoping somebody with some experience in generating XML from SQL will be able to point me in the right direction (or tell me what I'm

how to generate xml with element and attribute using xml explicit

这一生的挚爱 提交于 2019-12-07 22:37:55
问题 im trying to generate xml in the following format: <Root> <Domain>Abc</Domain> <Name>Xyz</Name> <Contents> <Content> <ID>1</ID> <Value>Test 1</Value> <Record ID="1">Test 1</Record> </Content> <Content> <ID>2</ID> <Value>Test 2</Value> <Record ID="2">Test 2</Record> </Content> </Contents> </Root> My query is as follows: declare @TestTable table (ID int, Value varchar(100)) insert into @TestTable values (1,'Test 1') insert into @TestTable values (2,'Test 2') declare @Domain varchar(max)='Abc'

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"