June 2, 2014 at 12:49 pm
In Italy the tax office requires a complete seq. number for invoices 🙁
June 2, 2014 at 12:54 pm
vinpes (6/2/2014)
In Italy the tax office requires a complete seq. number for invoices 🙁
Can you just use a normal process (identity/sequence) for use in the system and then create another column for TaxOfficeInvoiceNumber. Then once a day (or whatever interval) update your base table using ROW_NUMBER or similar? Would something like that be sufficient?
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
June 2, 2014 at 12:55 pm
vinpes (6/2/2014)
In Italy the tax office requires a complete seq. number for invoices 🙁
Yes, I have read about that sort of thing in the EU in general. But from what I read that doesn't preclude having VOIDED invoice numbers, unless you can find some references to the contrary.
June 2, 2014 at 1:04 pm
Hi Sean,
Can u provide to me an example, pls?
June 3, 2014 at 1:27 pm
Yeah, no gaps will be a royal pain to implement.
If you can allow "voided" gaps, then I think a standard identity would handle this, don't see the need for using a sequence. The identity is simply reseeded every Jan 01 at midnight with YYYY000001 (which could still be just an int and last through year 2146).
SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".
June 3, 2014 at 5:13 pm
Here is one way, which may or may not work for you.
Have a table of Invoice Numbers.
create table InvoiceNumbers(InvoiceNumber int);
create unique clustered index ci_InvoiceNumbers on InvoiceNumbers (InvoiceNumber DESC) WITH(FILLFACTOR=100);
insert invoicenumbers(invoicenumber)
select top(1000000) 2014000000 + row_number() over(order by (select null))
from sys.all_columns a, sys.all_columns b;
When you want one, DELETE it and OUTPUT the one you deleted.
Make sure you COMMIT this straight away, so as not to block anyone else.
declare @nextnum table(InvoiceNumber int);
begin tran;
begin try
with data as (select top(1) invoicenumber from invoicenumbers order by invoicenumber asc)
delete data
output deleted.invoicenumber into @nextnum(invoicenumber);
end try
begin catch
-- failed to get an invoice number, do some error handling
end catch
commit;
IF you need to rollback the transaction and re-use the invoice number, just INSERT it back into the pool...
Make sure this happens in an isolated transaction, AFTER you ROLLBACK your Invoice Creation transaction.
begin tran;
insert invoicenumbers(invoicenumber)
select invoicenumber
from @nextnum;
commit;
On my quick test, (just using three query sessions with GO 10000) on a desktop PC , this can push Invoice Numbers as fast as the machine can request them (GO 10000 is not that quick a method, so only ran at about 300 invoice numbers per second on each thread)
MM
select geometry::STGeomFromWKB(0x0106000000020000000103000000010000000B0000001000000000000840000000000000003DD8CCCCCCCCCC0840000000000000003DD8CCCCCCCCCC08408014AE47E17AFC3F040000000000104000CDCCCCCCCCEC3F9C999999999913408014AE47E17AFC3F9C99999999991340000000000000003D0000000000001440000000000000003D000000000000144000000000000000400400000000001040000000000000F03F100000000000084000000000000000401000000000000840000000000000003D0103000000010000000B000000000000000000143D000000000000003D009E99999999B93F000000000000003D009E99999999B93F8014AE47E17AFC3F400000000000F03F00CDCCCCCCCCEC3FA06666666666FE3F8014AE47E17AFC3FA06666666666FE3F000000000000003D1800000000000040000000000000003D18000000000000400000000000000040400000000000F03F000000000000F03F000000000000143D0000000000000040000000000000143D000000000000003D, 0);
June 4, 2014 at 5:14 am
For those attempting to help, I found this link that explains the requirements
There are 2 possible solutions, the first is the simple prefilled table with a flag to show if it has been activated or is available, and the row gets added back to the pool.
The second option is to create the ODN once the invoice has been created and committed as a final update.
This means having two numbers, and internal Invoice number and the public ODN, this allows the internal invoice number to have gaps while maintaining the sequential nature of the ODN, which is only generated after the invoice has been committed successfully.
_________________________________________________________________________
SSC Guide to Posting and Best Practices
June 4, 2014 at 7:19 am
Jason-299789 (6/4/2014)
For those attempting to help, I found this link that explains the requirementsThere are 2 possible solutions, the first is the simple prefilled table with a flag to show if it has been activated or is available, and the row gets added back to the pool.
The second option is to create the ODN once the invoice has been created and committed as a final update.
This means having two numbers, and internal Invoice number and the public ODN, this allows the internal invoice number to have gaps while maintaining the sequential nature of the ODN, which is only generated after the invoice has been committed successfully.
That second option is exactly what I was suggesting the OP could use but wasn't sure if that was allowed or not...apparently it is.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
June 4, 2014 at 1:03 pm
Sorry guys, but I dont understand how to implement it via SQL server....:w00t:
Viewing 9 posts - 16 through 23 (of 23 total)
You must be logged in to reply to this topic. Login to reply