| 订阅 | 在线投稿
分享
 
 
当前位置: 王朝网络 >> mssql >> SQL Server zhong duo xing duo lie lian jie cheng wei dan xing dan lie
 

SQL Server zhong duo xing duo lie lian jie cheng wei dan xing dan lie

2008-07-22 05:34:16 编辑來源:互联网 评论
 
本文为【SQL Server中多行多列连接成为单行单列】的拼音翻译版
  yuan shi jie gou :
  Column1 Column2
  ----------- ----------
  1 A
  1 B
  2 C
  2 D
  2 E
  3 F
  cha xun xiao guo :
  Column1 Column2
  ----------- ------------------
  1 A,B
  2 C,D,E
  3 F
  ji jiang Column1 xiang tong de xing de Column2 lian cheng yi lie 。
  bu zhi ru he miao shu ci zhong yong fa , shi fou ju you xiang jiao cha biao xiang guan de Cross-Table he Pivot zhi lei de yue ding cheng shu de zhuan ye cheng wei ?
  shi fou ye ke yi cheng wei ling yi zhong Cross-Table ?
  ci xu qiu ying gai shi chang jian de , wang shang ye you xu duo DEMO, zhi shi CSDN zhong pin fan you xin shou ti wen , xian jian dan shi xian yi ge DEMO, yi bian shen kao 。
  -- duo xing duo lie lian jie cheng wei dan xing dan lie shi li : xu yao yi ge zi ding yi han shu
  -- http://community.csdn.net/Expert/TopicView3.asp?id=5603231
  if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[VertToHorzSample]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
  drop table [dbo].[VertToHorzSample]
  GO
  -- jian li ce shi shu ju
  CREATE TABLE VertToHorzSample(
  Column1 int,
  Column2 varchar(100)
  )
  GO
  INSERT INTO VertToHorzSample(Column1, Column2)
  SELECT 1, 'A'
  UNION ALL
  SELECT 1, 'B'
  UNION ALL
  SELECT 2, 'C'
  UNION ALL
  SELECT 2, 'D'
  UNION ALL
  SELECT 2, 'E'
  UNION ALL
  SELECT 3, 'F'
  GO
  if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[ConvertVertToHorz]') and xtype in (N'FN', N'IF', N'TF'))
  drop function [dbo].[ConvertVertToHorz]
  GO
  -- jian li fu zhu han shu
  CREATE FUNCTION ConvertVertToHorz(@Col1Val int)
  RETURNS VARCHAR(8000)
  AS
  BEGIN
  -- shi ji xiang mu zhong , ying gai kao lv @RetVal shi fou hui chao guo 8000 ge zi fu
  DECLARE @RetVal varchar(8000)
  SET @RetVal = ''
  -- tong guo di gui SELECT lian jie zhi ding lie cun chu dao lin shi bian liang zhong
  SELECT @RetVal = Column2 + ',' + @RetVal FROM VertToHorzSample WHERE Column1 = @Col1Val
  -- lian jie duo lie
  -- SELECT @RetVal = Column2 + ',' + Column3 + ',' + Column4 + ',' + @RetVal FROM VertToHorzSample WHERE Column1 = @Col1Val
  -- qu diao yi ba de , ( dou hao )
  IF LEN(@RetVal) > 0
  SET @RetVal = LEFT(@RetVal, LEN(@RetVal) - 1)
  --PRINT @RetVal
  RETURN @RetVal
  END
  GO
  -- ce shi
  SELECT Column1, dbo.ConvertVertToHorz(Column1) Column2 FROM (SELECT DISTINCT Column1 FROM VertToHorzSample) t
  /**//*
  Column1 Column2
  ----------- ------------------
  1 A,B
  2 C,D,E
  3 F
  */
  GO
  if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[VertToHorzView]') and OBJECTPROPERTY(id, N'IsView') = 1)
  drop view [dbo].[VertToHorzView]
  GO
  -- ke yi jian li yi ge shi tu
  CREATE VIEW dbo.VertToHorzView
  AS
  SELECT Column1, dbo.ConvertVertToHorz(Column1) Column2
  FROM (SELECT DISTINCT Column1 FROM dbo.VertToHorzSample) t
  GO
  -- ce shi shi tu
  SELECT * FROM VertToHorzView
  /**//*
  Column1 Column2s
  ----------- -----------------
  1 A,B
  2 C,D,E
  3 F
  */【原文】【汉音对照
 
 
 
 
 
 
 
 
日版宠物情人插曲《Winding Road》歌词

日版宠物情人2017的插曲,很带节奏感,日语的,女生唱的。 最后听见是在第8集的时候女主手割伤了,然后男主用嘴帮她吸了一下,插曲就出来了。 歌手:Def...

兄弟共妻,我成了他们夜里的美食

老钟家的两个儿子很特别,就是跟其他的人不太一样,魔一般的执着。兄弟俩都到了要结婚的年龄了,不管自家老爹怎么磨破嘴皮子,兄弟俩说不娶就不娶,老父母为兄弟两操碎了心...

如何磨出破洞牛仔裤?牛仔裤怎么剪破洞?

把牛仔裤磨出有线的破洞 1、具体工具就是磨脚石,下面垫一个硬物,然后用磨脚石一直磨一直磨,到把那块磨薄了,用手撕开就好了。出来的洞啊很自然的。需要猫须的话调几...

我就是扫描下图得到了敬业福和爱国福

先来看下敬业福和爱国福 今年春节,支付宝再次推出了“五福红包”活动,表示要“把欠大家的敬业福都还给大家”。 今天该活动正式启动,和去年一样,需要收集“五福”...

冰箱异味产生的原因和臭味去除的方法

有时候我们打开冰箱就会闻到一股异味,冰箱里的这种异味是因为一些物质发出的气味的混合体,闻起来让人恶心。 产生这些异味的主要原因有以下几点。 1、很多人有这种习...

 
 
yuan shi jie gou : Column1 Column2 ----------- ---------- 1 A 1 B 2 C 2 D 2 E 3 F cha xun xiao guo : Column1 Column2 ----------- ------------------ 1 A,B 2 C,D,E 3 F ji jiang Column1 xiang tong de xing de Column2 lian cheng yi lie 。 bu zhi ru he miao shu ci zhong yong fa , shi fou ju you xiang jiao cha biao xiang guan de Cross-Table he Pivot zhi lei de yue ding cheng shu de zhuan ye cheng wei ? shi fou ye ke yi cheng wei ling yi zhong Cross-Table ? ci xu qiu ying gai shi chang jian de , wang shang ye you xu duo DEMO, zhi shi CSDN zhong pin fan you xin shou ti wen , xian jian dan shi xian yi ge DEMO, yi bian shen kao 。 -- duo xing duo lie lian jie cheng wei dan xing dan lie shi li : xu yao yi ge zi ding yi han shu -- [url=http://community.csdn.net/Expert/TopicView3.asp?id=5603231]http://community.csdn.net/Expert/TopicView3.asp?id=5603231[/url] if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[VertToHorzSample]') and OBJECTPROPERTY(id, N'IsUserTable') = 1) drop table [dbo].[VertToHorzSample] GO -- jian li ce shi shu ju CREATE TABLE VertToHorzSample( Column1 int, Column2 varchar(100) ) GO INSERT INTO VertToHorzSample(Column1, Column2) SELECT 1, 'A' UNION ALL SELECT 1, 'B' UNION ALL SELECT 2, 'C' UNION ALL SELECT 2, 'D' UNION ALL SELECT 2, 'E' UNION ALL SELECT 3, 'F' GO if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[ConvertVertToHorz]') and xtype in (N'FN', N'IF', N'TF')) drop function [dbo].[ConvertVertToHorz] GO -- jian li fu zhu han shu CREATE FUNCTION ConvertVertToHorz(@Col1Val int) RETURNS VARCHAR(8000) AS BEGIN -- shi ji xiang mu zhong , ying gai kao lv @RetVal shi fou hui chao guo 8000 ge zi fu DECLARE @RetVal varchar(8000) SET @RetVal = '' -- tong guo di gui SELECT lian jie zhi ding lie cun chu dao lin shi bian liang zhong SELECT @RetVal = Column2 + ',' + @RetVal FROM VertToHorzSample WHERE Column1 = @Col1Val -- lian jie duo lie -- SELECT @RetVal = Column2 + ',' + Column3 + ',' + Column4 + ',' + @RetVal FROM VertToHorzSample WHERE Column1 = @Col1Val -- qu diao yi ba de , ( dou hao ) IF LEN(@RetVal) > 0 SET @RetVal = LEFT(@RetVal, LEN(@RetVal) - 1) --PRINT @RetVal RETURN @RetVal END GO -- ce shi SELECT Column1, dbo.ConvertVertToHorz(Column1) Column2 FROM (SELECT DISTINCT Column1 FROM VertToHorzSample) t /**//* Column1 Column2 ----------- ------------------ 1 A,B 2 C,D,E 3 F */ GO if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[VertToHorzView]') and OBJECTPROPERTY(id, N'IsView') = 1) drop view [dbo].[VertToHorzView] GO -- ke yi jian li yi ge shi tu CREATE VIEW dbo.VertToHorzView AS SELECT Column1, dbo.ConvertVertToHorz(Column1) Column2 FROM (SELECT DISTINCT Column1 FROM dbo.VertToHorzSample) t GO -- ce shi shi tu SELECT * FROM VertToHorzView /**//* Column1 Column2s ----------- ----------------- 1 A,B 2 C,D,E 3 F */
󰈣󰈤
  免责声明:本文仅代表作者个人观点,与王朝网络无关。王朝网络登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述,其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
追忆.绯红色的审判
新竹的果子风
热裤女孩
凯宾斯基酒店随拍
金色草原
菜园小品
情人谷
广东惠州—巽寮湾的海景
 
>>返回首页<<
 为你推荐
 
 
 转载本文
 UBB代码 HTML代码
复制到剪贴板...
 
 热帖排行
 
 
 
 
©2005- 王朝网络 版权所有