正在创建用于递增数据库的逻辑.... [英] Creating a logic for incrementing in database....

查看:99
本文介绍了正在创建用于递增数据库的逻辑....的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



最近,我的老板要求我创建一个功能,其中特定付款单的订单数量会随单据数量增加.就像这样:
如果我的发票单号是12,并且有多个订单,那么订单数应该是这样-1201、1202、1203 ....依此类推.
我如何创建一种方法,该方法首次从数据库中选择发票编号,并在其末尾添加o01.然后在下一次始终应自动增加订单号.我脑子里有个想法,我可以在发票号上加上01,但如何确保仅在第一次使用.对于其他所有时间,应增加现有的工作订单数量. ?
请提出一个想法.

Hi,

Recently my boss asked me to create a functionality where the number of orders for a particular payment slip increments with the slip number. It is something like this:
If my invoice slip number is 12 and it has multiple orders so the number of orders should be like this - 1201, 1202, 1203 ....and so on.
How can i create a method which first time picks the invoice number from data base and add o01 at its end. And then for next time always it should inc the order number automatically. I have a idea in my mind where i can inc the invoice number by 01 but how to make sure it goes for the first time only. for all other times the existing work order numb should be increased. ?
Please suggest a idea.

推荐答案

在我看来,这是您在查询数据时应该执行的操作,并且不应该将该信息存储在数据库中.如果删除记录,在其他记录之间添加记录等,则数字可能会更改.计算的项目通常不应存储.

要在查询中获取序数,可以使用 ROW_NUMBER [
In my opinion this is something you should do when you query the data and you should not store that information in the database. The numbers may change if records are deleted, added between other records and so on. Calculated items shouldn''t be generally stored.

To get the ordinal number in a query you can use ROW_NUMBER [^]

Depending on the situation you can get the slip number and the row number in separate columns and format them at client side (concatenate etc). Of course they can be converted to character and concatenated in the SQL statement but typically formatting shouldn''t be done with SQL


这篇关于正在创建用于递增数据库的逻辑....的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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