DB2 SQL。使用Alpha和Numeric字段在订单上使用订单上的案例语句
我正在尝试按子句中的命令语句使用案例语句,但没有成功,因为一个字段是char,一个字段是数字。如果我在数字周围放一个char(),我不会得到我需要的排序 有没有一种方法可以与零一起使用以使其正确分类? 代码:
Order by
Case
When :SortBy = 'I' then LProd <-- Char
When :SortBy = 'L' then Char(LLine) <-- Numeric
End;
有人对如何执行此操作有任何想法吗?
I am attempting to use a case statement in my order by clause but am unsuccessful because one field is char and one field is numeric. If I put a Char() around the numeric, I don't get the sort I need because it is three byte numeric, 1, 2, 3. Which sorts in char() like 1, 10, 100, 2, etc
Is there a way to pad with zeros so that it sorts properly?
Code:
Order by
Case
When :SortBy = 'I' then LProd <-- Char
When :SortBy = 'L' then Char(LLine) <-- Numeric
End;
Does anyone have an idea on how to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试
digits()
try
DIGITS()
您可以使用CTE(常见的表表达式)按LPROD进行一阶,并给出等级(数字值)。然后从该CTE中选择并使用您需要的东西订购,因为两者都是数字。
You can use cte(common table expression) to first order by LProd and give it a rank(numeric value). And then select from that cte and order with what ever you need because both will be numeric.
Here is a demo