日期:2014-05-18 浏览次数:20566 次
if object_id('[tb]') is not null drop table [tb] go create table [tb]([ProductCode] int,[ProductName] varchar(7),[Type] varchar(4),[PackCode] varchar(8),[PackName] varchar(7),[PackType] varchar(4)) insert [tb] select 400,'乐斯本','208L','00240781','乐斯本','大桶' union all select 400,'乐斯本','208L','00240786','乐斯本','标签' union all select 400,'乐斯本','208L','00241150','乐斯本','瓶子' union all select 400,'乐斯本','208L','00341260','乐斯本','卷膜' union all select 401,'乐斯本2','218L','00341261','乐斯本2','卷膜' go select ProductCode,ProductName,Type, Msg=stuff((select ','+PackCode+PackName+PackType from tb where ProductCode=t.ProductCode for xml path('')),1,1,'') from tb t group by ProductCode,ProductName,Type /** ProductCode ProductName Type Msg ----------- ----------- ---- ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------