在 SQL Server 中,如何将多行数据变成一个字符串保存. skill 投石 挖矿 刮痧 上面三行数据想要得到结果为:投石,挖矿,刮痧 有两种方式: 拼接字符串. 使用 for XML 首先创建模拟用的数据 IF OBJECT_ID('tempdb..#TempTable') IS NOT NULL BEGIN DROP TABLE #TempTable; END CREATE TABLE #TempTable ( [name] VARCHAR(MAX), [skill] VARCHAR(
--将行转为字符串 select stuff((select top 20 ','+ QQ from dl_QQ where uiid=1 order by tim desc for xml path('')),1,1,'') -- ============================================= -- Description: 将字符串转为表格 /* 例:select * from [f_split]('spu0987*5//spu0988*5/spu0989*5',
select ptl_a01, ptl_piitem, ( ) as ptl_count, STUFF((SELECT ','+ltrim(ptl_pdid) FROM PRODUCT_TRACEABILITY_LOG , , '') AS ptl_all_pdid GROUP BY t.ptl_a01,t.ptl_piitem ORDER BY t.ptl_a01 关键字:STUFF 1.作用 删除指定长度的字符,并在指定的起点处插入另一组字符. 2.语法 STUFF ( character_
由于项目的原因,需要将一些记录分类汇总,但还要列出相关的明细,这样的需求我还是第一次遇到,蛋疼了,还是请求一下度娘吧.搜索一番还是有结果,请看以下例子: create table tb ([id] int,[name] varchar(2))insert into tbselect 1,'aa' union allselect 2,'bb' union allselect 1,'cc' union allselect 3,'dd' union allselect 2,'ee' select *
The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility) P A H N A P L S I I G Y I R And then read line by line: "PAHNAPLSII
转自:http://www.maomao365.com/?p=6410 摘要: 下文主要分享从指定字符串或列中获取数字信息,如下所示: 实验环境:sql server 2000 ----编写sql函数 )) ) as begin begin , ''); end; return @tmp; end go ----测试sql函数 SELECT dbo.getShuZi('猫猫小屋maomao365.com-sql教程专用网站') go drop function dbo.getShuZi go
create table tb ([id] )) insert into tb ,'aa' union all ,'bb' union all ,'cc' union all ,'dd' union all ,'ee' select * from tb --查询 select id, name=stuff((,,'') from tb t group by id 方法二: CREATE FUNCTION GET_STRING(@ID INT) RETURNS VARCHAR() AS BEGIN
SQL Server中行列转换 Pivot UnPivot PIVOT用于将列值旋转为列名(即行转列),在SQL Server 2000可以用聚合函数配合CASE语句实现 PIVOT的一般语法是:PIVOT(聚合函数(列) FOR 列 in (…) )AS P 完整语法: table_source PIVOT( 聚合函数(value_column) FOR pivot_column IN(<column_list>) ) UNPIVOT用于将列明转为列值(即列转行),在SQL Server 2