www-uweier-com

oralce写法:

select WM_CONCAT(A.title) as citys from tmpcity A

 

sql server写法:

select stuff((select \',\'+A.title from tmpCity A FOR xml PATH(\'\')), 1, 1, \'\') as citys

 

mysql写法:

select GROUP_CONCAT(A.title) as citys from tmpcity A; --默认的逗号分隔
select GROUP_CONCAT(A.title SEPARATOR \' \') as citys from tmpcity A; --用空格分隔

 

DECLARE @str VARCHAR(max)

SET @str=\'\'--必须要初始为空字符串(否则结果显示NULL)

SELECT @str = @str + \',\' + Cast(name AS VARCHAR(max)) FROM Student

SELECT @str

SELECT Stuff(@str, 1, 1, \'\')

 

*Stuff 函数用法:

以下示例从第一个字符串 abcdef 的第 2 个位置 (b) 开始删除三个字符,

然后在删除位置插入第二个字符串,从而创建并返回一个字符串。

select stuff(\'abcdef\', 2, 3, \'ijklmn\');

结果集:aijklmnef

分类:

技术点:

相关文章:

  • 2021-11-13
  • 2022-12-23
  • 2021-08-16
  • 2021-05-05
  • 2022-12-23
  • 2021-12-23
  • 2021-11-23
  • 2022-02-13
猜你喜欢
  • 2022-02-01
  • 2022-01-08
  • 2022-12-23
  • 2021-11-21
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案