小编dan*_*san的帖子

SQL Server'FOR XML'将值赋入"row"元素节点

这是另一个"for xml"问题,但我不确定这是否可以在没有显式模式的情况下完成.如果它不能,那么我将不得不忍受它.

以下是我目前的select语句:

    SELECT
        [stream_id] as '@stream_id',
        [path_locator] as '@path_locator',
        [parent_path_locator] as '@parent_path_locatr',
        [file_type] as '@file_type',
        [cached_file_size] as '@cached_file_size',
        [creation_time] as '@creation_time',
        [last_write_time] as '@last_write_time',
        [last_access_time] as '@last_access_time',
        [is_directory] as '@is_directory',
        [is_offline] as '@is_offline',
        [is_hidden] as '@is_hidden',
        [is_readonly] as '@is_readonly',
        [is_archive] as '@is_archive',
        [is_system] as '@is_system',
        [is_temporary] as '@is_temporary',
        [name] as '/name',
        dbo.udf_GetChildren(path_locator)
    FROM @Merged
    WHERE path_locator.GetLevel() = 1
    FOR XML PATH'file'), ROOT('files'), TYPE
Run Code Online (Sandbox Code Playgroud)

这将输出以下xml:

 <files>
   <file stream_id="" etc...>
      <name>NAME</name>
   </file>
 </files>
Run Code Online (Sandbox Code Playgroud)

这不错,但我真正喜欢的是将name元素的值作为file元素的值.这是一个如此简单的任务我认为它可以在没有显式模式的情况下完成,但我经常对这些事情做错.

我已经尝试使用'/'标记,但这似乎没有我想要的效果(例如SQL Server …

xml t-sql sql-server for-xml

5
推荐指数
1
解决办法
1704
查看次数

标签 统计

for-xml ×1

sql-server ×1

t-sql ×1

xml ×1