相关疑难解决方法(0)

nvarchar concatenation/index/nvarchar(max)莫名其妙的行为

我今天在SQL Server(2008R2和2012)中遇到了一个非常奇怪的问题.我正在尝试使用串联和select语句来构建字符串.

我找到了解决方法,但我真的很想了解这里发生了什么以及为什么它没有给我预期的结果.有人可以向我解释一下吗?

http://sqlfiddle.com/#!6/7438a/1

根据要求,这里的代码也是:

-- base table
create table bla (
    [id] int identity(1,1) primary key,
    [priority] int,
    [msg] nvarchar(max),
    [autofix] bit
)

-- table without primary key on id column
create table bla2 (
    [id] int identity(1,1),
    [priority] int,
    [msg] nvarchar(max),
    [autofix] bit
)

-- table with nvarchar(1000) instead of max
create table bla3 (
    [id] int identity(1,1) primary key,
    [priority] int,
    [msg] nvarchar(1000),
    [autofix] bit
)

-- fill the three tables with the same values …
Run Code Online (Sandbox Code Playgroud)

sql-server nvarchar string-concatenation sql-server-2012

12
推荐指数
1
解决办法
4765
查看次数

将行值合并为CSV(对于SQL Server,也称为GROUP_CONCAT)

我有一张桌子:

EntityID   AttributeID  OptionText
5016       20           Paintings
5044       18           Female
5060       48           M
5060       48           F
5060       49           Apple
5060       49           Banana
5060       49           Cat
Run Code Online (Sandbox Code Playgroud)

我想创建一个将显示的视图:

5016    20   Paintings
5044    18   Female
5060    48   M,F
5060    49   Apple, Banana, Cat
Run Code Online (Sandbox Code Playgroud)

均值每个实体的属性值应以逗号分隔显示.

选项的数量可以变化.

任何帮助表示赞赏!

sql sql-server

10
推荐指数
1
解决办法
5413
查看次数

FOR SQL Server中的XML PATH和[text()]

我在互联网上找到一些文章这个网址

然后我像这样编码查询,我得到相同的结果

但是当我改变AS [text()][name]

结果包含XML标记

像这样

在此输入图像描述

所以我的问题是[text()]这段代码中的内容

谢谢.

sql sql-server sql-server-2012

2
推荐指数
1
解决办法
7482
查看次数