通过在两列中记录ASC

时间:2019-03-11 08:08:27

标签: c# form-load

我正在尝试在Windows应用程序中以大声的形式订购。我尝试使用以下代码:

using (SqlCommand sqlcomm = new SqlCommand("SELECT * FROM remaining WHERE username=@username and status=@status and company_status=@company_status ORDER BY call_case ASC , Payment_Status ASC", sqlconn))

这是正确的方法吗?

我要查找的是OrderBy(call_case)ASC,以及当call_case =(2-Answer)OrderBy(Payment_Status)ASC时。

 (  call_case ), ( Payment_Status )

   null    ,    null 

   1-No Answer ,    null

   2-answer    ,    1-Promise Payment

   2-answer    ,    2-Have Problem

   2-answer    ,    3-Reject Payment

   3- not Exist ,      null
  

请注意,以1-No Answer,2-answer,3- Not Exist这类数字开头的文本

1 个答案:

答案 0 :(得分:1)

您可以将CASE表达式与ORDER BY一起使用

SELECT * FROM remaining 
WHERE username=@username 
and status=@status 
and company_status=@company_status 
ORDER BY      
   case when call_case='Answer' then 0 else 1 end ASC,      
   Payment_Status ASC