问题描述
我正在尝试在窗口应用程序中以大胆的形式订购OrderBy。我尝试使用这段代码:
I'm trying to OrderBy in form loud my columns in windows application. I try to use this code:
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。
Is that the right way to do it?
What I'm looking for is to OrderBy (call_case) ASC, and when 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
我有一个注释,我的帮助文本以nu开头mber喜欢1-No Answer,2-answer,3- not存在
我尝试过:
i have a note it my be help the text start with number like 1-No Answer , 2-answer , 3- not Exist
What I have tried:
SELECT * FROM remaining
WHERE username=@username
and status=@status
and company_status=@company_status
ORDER BY
case when call_case='2-Answer' then 0 else 1 end ASC,
Payment_Status ASC
推荐答案
;with cte as
(
SELECT *,
CASE WHEN call_case = '2-Answer' THEN 0 ELSE 1 END AS CallCaseOrder
FROM dbo.remaining
WHERE username = @username
AND status = @status
AND company_status = @company_status,
)
SELECt * FROM cte
ORDER BY CallCaseOrder, PaymentStatus;
我认为这更容易阅读。我也会避免使用 SELECT *
。这是不好的做法,你不能告诉它不要在返回的数据集中包含你的 CallCaseOrder
。
I think that's much easier to read. I also would avoid using "SELECT *
". It's bad practice, and you can't tell it not to include your CallCaseOrder
in the returned dataset.
这篇关于订单在两列中记录ASC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!