Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server Sql:使用通过xmlPath获得的特定字符串更新行_Sql Server_Sql Update_For Xml Path - Fatal编程技术网

Sql server Sql:使用通过xmlPath获得的特定字符串更新行

Sql server Sql:使用通过xmlPath获得的特定字符串更新行,sql-server,sql-update,for-xml-path,Sql Server,Sql Update,For Xml Path,我必须用xmlpath获得的具体字符串的结果更新表列 例如,我必须做那样的事情 Update table c set c.languages = (SELECT '\r\n'+rl.Name AS [text()] from ResourceLanguage as rl where rl.resource_Id=c.resource_Id FOR XML PATH ('')) 我得到一个错误“c附近的语法不正确” 在我的例子中,字段语言是nvarchar(

我必须用xmlpath获得的具体字符串的结果更新表列

例如,我必须做那样的事情

Update table c
set c.languages = 
(SELECT '\r\n'+rl.Name AS [text()] 
    from ResourceLanguage as rl 
        where rl.resource_Id=c.resource_Id
    FOR XML PATH (''))
我得到一个错误“c附近的语法不正确”

在我的例子中,字段语言是nvarchar(max)类型

有人能帮我吗? 谢谢你这样写 可能对你有帮助

这是一个演示代码,您必须这样尝试:

UPDATE    Table_1

SET    c =

(

SELECT ( SELECT 'White' AS Color1,

'Blue' AS Color2,

'Black' AS Color3,

'Light' AS 'Color4/@Special',

'Green' AS Color4,

'Red' AS Color5

FOR

XML PATH('Colors'),

TYPE

),

( SELECT 'Apple' AS Fruits1,

'Pineapple' AS Fruits2,

'Grapes' AS Fruits3,

'Melon' AS Fruits4

FOR

XML PATH('Fruits'),

TYPE

)
FOR XML PATH(''),

ROOT('SampleXML'))
我找到了解决办法。 这是:

 DECLARE @tempTable TABLE
(
    Id int,
    Languages nvarchar(max)
)

INSERT @tempTable (Id, Languages )
(
    select r1.resource_Id, Stuff((select', '+ rl.Name as [text()]
      from ResourceLanguage as rl 
      where rl.resource_Id=c.resource_Id
      for xml path(''), type).value('.', 'nvarchar(250)'), 1, 2, '')
    from Resource r1
)

Update Resource 
Set Languages = temp.Languages 
    FROM @tempTable temp  
    where resource_Id=temp.resource_Id

c.languages
c.resource\u Id
中删除
c
。谢谢。但仍然不起作用。我在关键字“FROM”(在第一个FROM上)附近发现错误语法