如何在SQL Server中按状态码排列 [英] how to arrange by status code in sql server

查看:122
本文介绍了如何在SQL Server中按状态码排列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,
我有一张桌子,我要根据给定的代码formate
安排此桌子的值
这是状态表

Dear all,
i have a table i want to arrange this table value given code formate

it is Status table

statuscode	        statusid	StatusCount

Just Received	           1	         7
Sent to Engineer	   2	        30
Estimation Not Approved	   4	         2
Under QC	           9	        17
QC Passed	           10	         1
Ready for Delivery	   11          159
Delivered to Customer	   13	       288
Reallocated to Engineer	   17	         1
Sent to HO / RO	           20	         3
Allocated to CSO	   21	         1
Pending For Estimation	   38	        21
Pending For Engineer Estimation	39	40
Pending For Estimation Approval	40	65
Estimation Approved	   41	        17
Pending Payment	           42	        48
Sent To QC Unrepaired	   43	        10
Payment Received	   44	        22





how to arreange by statuscode


Just Received
Pending For Estimation
Pending For Engineer Estimation
Pending For Estimation Approval
Estimation Not Approved	
Sent to Engineer
Under QC
QC Passed
Pending Payment	
Payment Received
.
.
.
.
.
.

推荐答案

您不能重排这些列.您可以做的是可以添加一个新的DisplayOrder列,您可以说它的显示顺序.
You cannot rearrage these columns. What you can do is you can add a new column DisplayOrder in whic you say the order in which it is to be displayed.
statuscode	        statusid	StatusCount   DisplayOrder
 
Just Received	           1	         7             1
Sent to Engineer	   2	        30
Estimation Not Approved	   4	         2             5
Under QC	           9	        17             6
QC Passed	           10	         1
Ready for Delivery	   11          159
Delivered to Customer	   13	       288
Reallocated to Engineer	   17	         1
Sent to HO / RO	           20	         3
Allocated to CSO	   21	         1
Pending For Estimation	   38	        21              2
Pending For Engineer Estimation	39	40              3
Pending For Estimation Approval	40	65              4
Estimation Approved	   41	        17
Pending Payment	           42	        48
Sent To QC Unrepaired	   43	        10
Payment Received	   44	        22




然后在检索时您可以说




Then when retrieveing You can say

select statuscode from status order by displayorder


添加另一列状态代码,并在选择时按状态代码排序记录
Add another column for status code and sort order by status code when select records


您将需要添加提供排序顺序的列,或者编写一个整体的CASE语句:
You will need to either add a column which provides the sort order, or write a monolithic CASE statement:
SELECT * FROM MyTable
   ORDER BY
     CASE statuscode
     WHEN 'Just Recieved' THEN 1
     WHEN 'Pending For Estimation' THEN 2
...
     ELSE 9999
     END

我自己添加该列!


这篇关于如何在SQL Server中按状态码排列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆