当前位置: 代码迷 >> Sql Server >> 急高手请帮忙,求一sql语句 把字段值横放 ,马上给分解决方案
  详细解决方案

急高手请帮忙,求一sql语句 把字段值横放 ,马上给分解决方案

热度:39   发布时间:2016-04-27 19:04:37.0
急!!高手请帮忙,求一sql语句 把字段值横放 ,马上给分
高手请帮忙,求一sql语句   把字段值横放  
表如下
table(id,A,B)   id,A,B为字段名  
------------------
id   |A       |         B|
  1       1     |       10|
  1       2     |       13|
  1       3     |       12|
  2       1     |       12|
  2       2     |       12|
  2       3     |       12|  

通过sql后表数剧变成(通过ID,A,B字段横放了)
               
---------------------
1     |   1   2   3   |   10   13   12
2     |   1   2   3   |   12   12   12


------解决方案--------------------
alter function f_gets(@id int)
returns varchar(2000)
as
begin
declare @s1 varchar(1000),@s2 varchar(1000)
select @s1= ' ',@s2= ' '
select @[email protected]+ ' | '+rtrim(A), @[email protected]+rtrim(B)+ ' | ' from tableA where [email protected]
return @s1+ ' | '[email protected]
end
  相关解决方案