选择最大发票号码的问题。用SQL查询... [英] problem with select maximum invoice no. with SQL query...
本文介绍了选择最大发票号码的问题。用SQL查询...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我运行此查询时: -
从BillDetails中选择max(BillNo),左边(BillNo,6)='13-14 /'
它只返回'13 -14/9'但我有账单 - 没有'13 -14/10'(这是最大值)..
我的账单没有这样的模式: -
'13 -14/1'
'13 -14/2'
'13 -14/3'
.....
'13 -14/10'
如何获得最高账单没有相同年份('13 -14 /')????
我正在使用MSAccess作为数据库..
感谢高级..
问候:
Jayanta ..
解决方案
< blockquote>尝试:
SELECT TOP 1 BillNo FROM BillDetails WHERE BillNo LIKE ' 13-14 /%' ORDER BY CAST(SUBSTRING(BillNo) , 7 , 999 ) AS INT )
您正在尝试根据解析字符串获取最大帐单编号。
结果,你不会得到确切的值,因为1和10在字符串中的比较不同。
您可以解析账单否如上所述,然后将该数字转换为整数以获得最大值。
When i run this query :-
select max(BillNo) from BillDetails where left(BillNo,6)='13-14/'
It's return only '13-14/9' but I have bill-no this '13-14/10'(which is maximum)..
My Bill No pattern like :-
'13-14/1'
'13-14/2'
'13-14/3'
.....
'13-14/10'
How to get maximum bill no of a same years('13-14/')????
I'm Using MSAccess as a Database..
Thanks in Advanced..
Regards:
Jayanta..
解决方案
Try:
SELECT TOP 1 BillNo FROM BillDetails WHERE BillNo LIKE '13-14/%' ORDER BY CAST(SUBSTRING(BillNo, 7, 999) AS INT)
You are trying to get the maximum bill number based on parsing a string.
As a result, you wont get the exact value since 1 and 10 are compared differently in string.
You could parse the bill no as above and then convert that number to integer to get the maximum value.
这篇关于选择最大发票号码的问题。用SQL查询...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文