本文介绍了如何将行转换为列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将行转换为列。这是我的样品表。



tbl_table



FId类型

6号码

8名称

15街道

18地址



这是查询我已经解决了。



 SELECT SUBSTRING((SELECT','+ CAST(FId AS VARCHAR)FROM tbl_table其中输入('地址','街道','数字','名称')FOR XML PATH('')),2,10000)AS FID 



我收到了输出为



FId

6,8,15,18



它已经将行转换为列,但我的问题是,



我需要输出相同的输出我输入的内容。



我的预期输出应为



FId

18,15,6,8





请妥善解决此问题。



我的尝试:



 SELECT SUBSTRING((SELECT','+ CAST(FId AS VARCHAR)来自tbl_table其中输入('地址','街道','数字','名称')FOR XML PATH('')),2,10000)AS FID 
解决方案



I want to convert rows into columns. here is my sample table.

tbl_table

FId Type
6 Number
8 Name
15 Street
18 Address

Here is the query I have worked out.

SELECT SUBSTRING((SELECT ',' + CAST(FId AS VARCHAR) FROM tbl_table where Type in('Address','Street','Number','Name')FOR XML PATH('')), 2,10000) AS FID


I received output as

FId
6,8,15,18

It has been converted rows into columns, But my problem is,

I need the output in same order which input i have passed inside.

My expected output should be as

FId
18,15,6,8


Kindly resolve this problem.

What I have tried:

SELECT SUBSTRING((SELECT ',' + CAST(FId AS VARCHAR) FROM tbl_table where Type in('Address','Street','Number','Name')FOR XML PATH('')), 2,10000) AS FID
解决方案



这篇关于如何将行转换为列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-11 15:26