I need to make some tables which are able to auto-increment unique document names for each month of the year based on the date of each documnet type. I think it will be a good idea to make it as a generated stored column in a MySql table. Thailand uses the Buddhist calendar where you normally add 543 years to the Christian calendar (2024 becomes 2567) in this case I add 43 years as I only need the last digits of the year. I am then missing the last serial number to number which I cannot find a solution to after intense searching on the internet. I would think it should be found under grouping. In this case, I am working with the invoices.
My table:
CREATE TABLE `tbl_0_invoices` (
`invoice_date` date NOT NULL,
`invoice_no` varchar(45) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci GENERATED ALWAYS AS (concat(_utf8mb4'INV',(date_format(`invoice_date`,_utf8mb4'%y') + 43),date_format(`invoice_date`,_utf8mb4'%m'))) STORED;
ALTER TABLE `tbl_0_invoices`
ADD PRIMARY KEY (`invoice_no`);
I have not been able to find any documentation on the issue, even this kind of document identification is quite normal in Thailand.
I expect this output.
| invoice_date | invoice_no |
|---|---|
| 21/8/2567 | INV6708-1 |
| 13/9/2567 | INV6709-1 |
| 13/9/2567 | INV6709-2 |
| 13/9/2567 | INV6709-3 |
| 13/9/2567 | INV6709-4 |
| 18/9/2567 | INV6709-5 |
| 25/10/2567 | INV6710-1 |
| 25/10/2567 | INV6710-2 |
| 25/10/2567 | INV6710-3 |
| 25/10/2567 | INV6710-4 |
| 24/1/2568 | INV6801-1 |

INV-6708-1,INV-6708-2,INV-6709-3where the serial incement is not reset every month?