--------------------SQL Server数据格式化工具------------------- --------------------------------------------------------------- -- DESIGNER :happycell188(喜喜) -- QQ :584738179 -- Development Tool :Microsoft Visual C++ 6.0 C Language -- FUNCTION :CONVERT DATA TO T-SQL --------------------------------------------------------------- -- Microsoft SQL Server 2005 -- Developer Edition on Microsoft Windows XP [版本 5.1.2600] --------------------------------------------------------------- --------------------------------------------------------------- use test go if object_id('test.dbo.tb') is not null drop table tb -- 创建数据表 create table tb ( col char(5) ) go --插入测试数据 insert into tb select 'jmtx' union all select 'hjcz' union all select 'jmxz' union all select 'cpxl' union all select 'hjxh' union all select 'czjb' go --代码实现 select distinct col=stuff((select ','+rtrim(col) from tb for xml path('')),1,1,'') from tb /*测试结果 col ----------------------------------- jmtx,hjcz,jmxz,cpxl,hjxh,czjb (1 行受影响) */ 有了!哈哈,不好意思 就是列转行显示!!问个问题都不专业,谢谢子夜。
use test go if object_id('test.dbo.tb') is not null drop table tb -- 创建数据表 create table tb ( col char(5) ) go --插入测试数据 insert into tb select 'jmtx' union all select 'hjcz' union all select 'jmxz' union all select 'cpxl' union all select 'hjxh' union all select 'czjb' go --代码实现 select distinct col=stuff((select ','+rtrim(col) from tb for xml path('')),1,1,'') from tb /*测试结果 col ----------------------------------- jmtx,hjcz,jmxz,cpxl,hjxh,czjb (1 行受影响) */
有了!哈哈,不好意思 就是列转行显示!!问个问题都不专业,谢谢子夜。