我创建了一个脚本,它从 SQL 中的表中获取数据并生成 XML 输出.父、子和子子标签对于 2 个标签都是相同的.SQL 脚本将它们作为一个 XML 值而不是 2 输出.
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]
目前的结果是:
<ActionFlags>
<Flag>DoDealValidateDoDealDerive</Flag>
</ActionFlags>
<ActionFlags>
<Flag>DoDealValidate</Flag>
<Flag>DoDealDerive</Flag>
</ActionFlags>
只需在中间放置一些空:
SELECT
'blah' AS [RequestHeader/RequestID],
'Deal.Trial' AS [RequestHeader/Action],
'DoDealValidate' AS [RequestHeader/ActionFlags/Flag],
NULL AS [RequestHeader/ActionFlags],
'DoDealDerive' AS [RequestHeader/ActionFlags/Flag]
FOR XML PATH('row');
背景:
引擎通过 SELECT 的列运行并一个接一个地构建它们.
The engine is running through the SELECT's columns and builds them one after the other.
要打开要打开,还是打开的,没什么...哦,我们必须关闭并打开一个新的<RequestHeader> to open<RequestID> to open<RequestHeader>, still open, nothin to to<Action> below... Oh, we must close the <RequestID> and open a new <Action>在您的代码中, 仍然是打开的,因此内容被写入到 open 元素中.
In your code the <Flag> is still open, therefore the content is written into the open element.
我的改变会让引擎思考
...哎呀,没什么可写的...<Flag>有一些东西,它不再打开了,我们必须重新打开一个(新的)节点立><Flag> first... Oops, there's nothing to write...<Flag>, which is not open anymore, we have to re-open a (new) <Flag> node这篇关于如何在 SQL 中拆分具有相同子子名称的两个 xml 标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
我可以在不编写 SQL 查询的情况下找出数据库列表Can I figure out a list of databases and the space used by SQL Server instances without writing SQL queries?(我可以在不编写 SQL 查询的情况下
如何创建对 SQL Server 实例的登录?How to create a login to a SQL Server instance?(如何创建对 SQL Server 实例的登录?)
如何通过注册表搜索知道SQL Server的版本和版本How to know the version and edition of SQL Server through registry search(如何通过注册表搜索知道SQL Server的版本和版本)
为什么会出现“数据类型转换错误"?使用 ExWhy do I get a quot;data type conversion errorquot; with ExecuteNonQuery()?(为什么会出现“数据类型转换错误?使用 ExecuteNonQuery()?)
如何将 DataGridView 中的图像显示到 PictureBox?How to show an image from a DataGridView to a PictureBox?(如何将 DataGridView 中的图像显示到 PictureBox?)
WinForms 应用程序设计——将文档从 SQL Server 移动WinForms application design - moving documents from SQL Server to file storage(WinForms 应用程序设计——将文档从 SQL Server 移动到文件存