Incrementing An Invoice Number
May 2, 2008
Hi there
I need a bit of generic advice about a project I am currently working on which is slightly out of my comfort zone. I€™m using SQL 2005 and VB.Net to develop an application that produces invoices for a number of different countries. The issue is that the data is arriving from an AS400 system so the tables I am working from are a little strange! This results in a fair degree of work tweaking the data into a format that is useful for my application.
To simplify the explanation each invoice in its basic form consists of the invoice data and the line items (so there is nothing new here). What is unusual is that the invoice data has an invoice number but then an additional invoice number specific to the country it is destined for. The initial invoice number arrives with the data from the AS400 but the secondary number is generated according to a number of business rules.
I have written an update query in a stored procedure which updates the invoice data with a number of values from a secondary table and a number of calculated values. There are several functions, one in particular which looks up the new invoice number from a secondary table based on specific criteria (country of destination being one of them) and I had intended to write an update query, called from within this function which then increments the invoice number but I have since found out that you cant do an update/delete from a function?
I can€™t add an update query to increment the value after the initial update query as this results in the stored procedure running through and adding all the invoice numbers (which are the same) and then the number being incremented at the end.
I assume I can€™t call an update query from within the initial update query so that the increment takes place after each loop of the initial update (if I can what would the syntax be?).
I have tried writing a trigger which completes the increment when the invoice data is updated. I haven€™t used triggers before but once again it appears as if the first update query is running through and completing all the updates and then the trigger fires incrementing the number. Or have I just got this wrong?
I guess what I need is a trigger which fires after each row of the table is updated which was how I assumed it should work!
Ironically I could write this in VB.Net with ease but for speed we need it within the database.
What is the best way to increment my invoice number?
I€™m sorry of this is general in nature but im really looking for some advice as to the best approach to deal with this issue.
Martyn Fewtrell
View 19 Replies
ADVERTISEMENT
Jun 30, 2014
I have a field type of char(7) which holds an invoice number.
It has leading zeros that i want to remove.
0000001 I would like to make it 1.
How can I remove the leading zeros. If I need to replace them with spaces that is fine too.
View 1 Replies
View Related
May 8, 2008
Can you help me with SQL issue I€™m stuck on?
I wish to take source data that looks like this:
Invoic_num
Line_num
6658
0
6658
2
6658
8
7721
2
7721
3
And rebuild the line numbers like this:
Invoic_num
Line_num
6658
1
6658
2
6658
3
7721
1
7721
2
This seems completely impossible to me. So I was thinking that maybe a second procedure using update could be run against the table after the initial build.
View 10 Replies
View Related
Feb 22, 2005
Hi, can anyone teach me how to automatic create a invoice number and insert or update it to a column?
View 2 Replies
View Related
May 31, 2014
I have a db to manage the creation of invoice number designed for a web application.
My problem is how to manage the concurrency when the users need to create an invoice number.
View 9 Replies
View Related
Jul 23, 2005
Sorry to bother you guys with what I though would be an easy task. Ihave a table in my database were I would like one of the rows toincrement a number for each row. I want the first row to start at 1000and keep on incrementing by 1 'till the end of the rows (about 2.7million rows). I though this would be a piece of cake, but I just can'tseem to find anything like it on the internet...weird.Anyways, I'm just a rookie in sql, any help would be appreciatedThanksJMT
View 6 Replies
View Related
Jul 15, 2015
I have four columns in my table, the first one is the identity column
col1 Col1 col2 col3
1 12 1 This is Test1
2 12 2 This is Test1
3 12 3 This is Test3
4 12 4 This is Test4
5 12 5 @@@@@
When, I see, @@@ sign in my col4, I need to restart the col3 from 1 again so it will look like this
col1 Col2 col3 col4
1 12 1 This is Test1
2 12 2 This is Test1
3 12 3 This is Test3
4 12 4 This is Test4
5 12 5 @@@@@
6 12 1 This is another test1
7 12 2 This is another Test2
Is it possible to do that?
View 8 Replies
View Related
Mar 11, 2008
My SQL table has the
following columns:
ID – Auto IncrementingNumber_of_Records – IntAccount_Number – Varchar
(Format 1234)Account_Number_Instance – Varchar
(Format e.g. 1234-01)Other_Field1Other_Field2…etc.
When the Account_Number was
initially inserted into the table, a Stored procedure (not written be me) was used to concatenate the Account_Number
and Number_of_Records. As a result
the Account_Number_Instance became,
e.g. 1234-01, etc.
From the ASPX form we
retrieve each of the fields above, and based on the Number_of_Records an
appropriate number of records were inserted for the Account_Number.
For Example:
Account_Number = 12345Number_of_Records = 4
The result inserted into the
table were as follows:
ID # of Records Acct_Number
New_Num Acct_Number_Instance …
1 4 12345 12345-01
2 4 12345 12345-02
3 4 12345 12345-03
4 4 12345 12345-04
Now, I would like to UPDATE
this table, and based on the original Number_of_ Records (4) I want to ADD, for
Account_Number (1234) add an appropriate Number_of_Instances, beginning with
the next incremental number and adding what the New Number of Records input is…
For Example:
Account_Number = 12345 New_Num(ber_Of Records) = 3
ID # of Records Acct_Number New_Num Acct_Number_Instance …
1 4 12345 12345-01
2 4 12345 12345-02
3 4 12345 12345-03
4 4 12345 12345-04
5 12345 3 12345-05
6 12345 3 12345-06
7 12345 3 12345-07
I
do realize that the next time I have to update this Account_Number I am also
going to have to somehow ADD only one of the #_of_Records and New_Num for the
Acct_Number instances to obtain the next starting number, which in the example
above would be (8)…
Any
and all suggestions on how to accomplish this would be greatly appreciated!
Thanks
View 2 Replies
View Related
Apr 14, 2006
hi!
i actually have more than question related to the SQL Server 2000
1) On my system I charge users for using an online service (SMS ) and I have a monthly fees charge and monthly allowance usage so if they exceed the limit I can also charge them for over usage this is an example for a rate that I have in my Rate Table
Rate Id = 1
MonthlyFees £10.0
MothlyAllowence = 100 sms/ month
Extra usage = 0.12 p for each extra SMS
The system should calculate the monthly invoice from the registration date so if you register in 14 April the invoice will be generated every month at the same day (15) each month.
Now! I need to generate and calculate the invoice …..Where shall I do the calculation? In the Business object Layer or in somewhere else? And for invoicing the client every month I might have 20 clients and each one might have different day so the billing should be auto generated also what properties or methods that can calculate or check monthly related to the day so it will run in the way like the phone bill!! any advice is appreciate it!
View 1 Replies
View Related
Nov 8, 2006
Please i have created some tables Delivary with this columns (DelivaryId,DelivaryNo,QtyRecieved,DelivaryDate,ProductId) and Product with this columns (ProductId,ProductCode,ProductName,ProductPrice) as you can see the product table keeps record of products whlie the delivary table keeps record of stock supplied. I will like to create another table that will keep record of stock sold out (Invoice Table) based on the qty recieved from the delivaries table
Please help
View 4 Replies
View Related
Mar 29, 2007
Just seeing if people have any suggestions for me on this problem, i am trying to produce some form of invoice for a company and finding that cursors if the best method due to having to format the invoice using sql server. However i have come across a problem in a section where i need to have the invoice address and a shipping address i am finding it hard to sort out the spacing for example
Print ' Invoice address'+''+' Shipping address '
Print @Customername+''+@Customername
Print @Address+''+@ShippingAddress
Print @City+''+@ShippingCity
Print @PostalCode+''+@ShippingPostalCode
Now the problem comes that for space reasons I have the datatype for the variables as varchar mainly but when running the report obviously its a problem that it appears disjointed
eg.
Alex JohnsonAlex Johnson
16 Stobson Street 16 Stobson Street
Leeds Leeds
LS12 6GHLS12 6GH
Now is there a way that this can be sorted like should I us char() datatype to specify the lengths,
Also is there a command the insert spaces instead of just using the quotation markers ' '
Cheers in advance sql people
View 4 Replies
View Related
Jan 4, 2007
Hi
I have a invoice that displays the company name in a rectangle on top then it has a list in the list it has details tables my problem is that the invoice detail goes on the next page I need to have the company name as well on the second page I cant put it in the same table as the detail because I have a few tables in the detail so it is actually no header is it possible to have Repeated the Company name information on the next page?
Thanks
View 4 Replies
View Related
Feb 6, 2007
Hi,
I need assistance with the following please.
I have to display the total for an invoice. The price for the products change over time.
I want the invoice date to correspond with the current period's price.
Thus if invoice date is y, it should calculate using the price between x and z.
Thanks,
Arend
View 7 Replies
View Related
Jul 20, 2007
Hi,
I want know if is possible create a report, with this caracteristics.
Page 1:
Header:
Nome of Company Invoice nº 1
Original
Detail:
line 1
line 2
line 3
Page 2:
Header:
Nome of Company Invoice nº 1
Copy
Detail:
line 1
line 2
line 3
.
.
.
Many pages of parameter in my code in Visual Studio.
Tanks,
Camsoft77
View 4 Replies
View Related
Oct 18, 2001
Hi,
I'm using SQL Server 7. I have two tables as follows:
Table Invoices:
CustNo
DocDate
Amount
Table Payments:
CustNo
DocDate
Amount
Can anyone think of a process to find the invoice with no payment for each customer? I need to do some kind of process of elimination; I suppose.
Any Suggestions?
Thanks,
Denise
View 3 Replies
View Related
Nov 2, 2015
I have a requirement to generate Invoice system for 1000 customers. how to create a report or SSIS Package to auto generate invoices everyday as per the start date of the customer.
View 1 Replies
View Related
Sep 7, 2007
I am using an invoice image that is preset and a fixed size. I am trying to lay text boxes on top of this image, but the boxes move around differently when you preview and/or print preview. If this is deployed, then the form prints and all of the text box information prints after the invoice image. Has any one experienced this before?
And one more question, is there a way to make a report a fixed length in size, ie, another invoice that might have 1 line or 23 lines and the total always needs to print at the bottom of the report and not move up the page. Is there a way to fix your report to accomodate for that? I have tried list box, matrix, etc and I am unable to find a solution to this.
Any help with either of these questions would be greatly appreciated!!!
View 6 Replies
View Related
Jun 30, 2007
Can anyone advise if it's viable to send order invoice reports to customers with SQL Reports.
I have a well formatted report that accepts an order number and generates an email to the customers address but i'm struggling on how to batch send this. Each order record has the email address to send to.
In our orders table I have a 'sent' flag so can easily write a query to bring back all orders that need sending. I just can't work out how to automate running the report for each order. Then after the report has been run for that order it needs to update the 'sent' flag.
Possibly this can work with a SSIS package that does the initial selection and updating of the flag but i can see how to run a report server report from an SSIS package.
Any ideas appreciated.
View 1 Replies
View Related
Feb 22, 2008
I have a report that prints 20+ invoices and I need a page break after each invoice.
STEPS TO REPRO:
1) Create a report to show an invoice (one row of data) using a query that pulls 20+ rows of invoice data.
2) Table Properties | "Insert a page break after this table" is checked.
RESULT:
1) 3-4 invoices appear on each page.
EXPECTED:
1) Page break after each invoice.
What is missing?
View 3 Replies
View Related
Oct 1, 2012
If you will I am trying to join a master invoice table to its detail records. The problem is I can't quite get the records to match correctly. There is a master record that has the net total of the invoice that corresponds to however many detail records for that invoice. I am attempting to get the records to line up in a query. I am having trouble because the key fields match the total up with each detail record. So for example in this record set below the 3825.75 value appears for each detail record so when I total the invoice column the figure is way too high. The detail has a 4462.54 and a -636.79 for a net of 3825.75. I tried to line the example up for better illustration. I copied it off a pdf and I am trying to replicate it programmatically.
0712RW-IN 7/31/2012 8/30/2012 4,462.54 0.00 3,825.75 INV 7/31/2012 4,462.54
C/M 8/31/2012 636.79- Reference: 0712RW
CREATE TABLE [dbo].[INVOICE](
[SRC] [varchar](3) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[ARDIVISIONNO] [varchar](2) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[CUSTOMERNO] [varchar](7) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[Code]....
View 1 Replies
View Related
Apr 3, 2008
Hi all - struggling a bit with this one... I have made an accounts application and need to make a report called "Aged Debtors". It lists all of the clients with outstanding invoices and breaks them down into periods:
current (this month)
period 1 (last month)
period 2 (2 months ago)
period 4 (invoices raised 3 months ago or more)
My tables are as follows (simplified)
Clients
clientid int
clientname varchar(100)
invoices
invoiceid int
clientid int
invoicedate datetime
cinvoiceamount decimal(19,2)
paid int (1 = paid, 0 = unpaid)
paidamount decimal(19,2) (how much of this invoice has been paid)
I need the following columns in the report
clientname invoiceid current period1 period2 period3+
test client 1 £100 - - -
2 £50 - - -
3 - £100 - -
test client2
I can format all the report using a matrix in SSRS so just need the stored proc to get me going - any help greatly appreciated!
Thanks guys,
Stephen.
View 5 Replies
View Related
Oct 13, 2014
I have a table with data like the following:
ClientID InvoiceDate
1 2012-01-01
1 2013-01-01
2 2012-01-01
2 2013-01-01
3 2012-01-01
3 2013-01-01
I would like to return a distinct ClientID and also the minimum InvoiceDate for that ClientID, so that the data looks like this:
ClientID InvoiceDate
1 2012-01-01
2 2012-01-01
3 2012-01-01
View 1 Replies
View Related
Jul 11, 2007
I need to create an invoice report, each page represents a single invoice. like a form report.
Which control is good, i am new to reports. i have used table control for few of our reports still learning.
Thank you very much for your help.
View 1 Replies
View Related
May 18, 2015
All I have a table full of invoices and in that table there is a field named HCC. An invoice can contain multiple HCC's. I also have a table named hierarchical codes (below is an example)
(COL1)HCC...........(COL2)If any of the HCCs in this column exist on an invoice along with the HCC in column 1 then use HCC listed in column one
1
2
3.......................4
4
6
8.......................9 ,10 ,11 ,12 ,13
[code]...
I want to return invoice 1 with HCC set to 34 since the hierarchy for when any of these HCCs (35 ,36 ,37 ,38) exist on an invoice along with 34 is 34.
View 4 Replies
View Related
Sep 25, 2015
i need to generate documents for customers to sign automatically as sales staff enter their data into SQL. These are invoice style documents. I currently have word templates of the invoice documentation, i just need to be able to add the clients names, address etc into the relevant spaces for them to print off and sign.
I am good with TSQL and writing Stored Procs etc and can easily get the data ready - i just need to find a way to populate the templates in the right places and then save a copy for emailing.
View 9 Replies
View Related
Nov 21, 2007
Hi,
I currently have a table which has around 60000 records, within the table there is a field which is acting as the Primary but the numbers are not in consecutive order any more (due to deletion), and i need a SQL Script that will start at the beginning of the records and UPDATE (STK_LOCATION) and SET the field (LOC_PRIMARY) to 1 on the first record and then go through the rest of the table setting the same field to +1 of the record before it.
Any help and advice will be very grateful
Thanks in advance
View 3 Replies
View Related
Apr 27, 2007
I have just started using SSIS this week. I am experienced with a different ETL tool (DataStage).
What I am trying to accomplish is the following:
Read the MaxValue of a Key from a Table and match to a stream of data using a LookUp stage.
Increment the value of each row for insertion to the table where I obtained the MaxValue.
What would seem to be a very simple procedure (I could knock this out in 10 minutes with DS...of course I have more experience with that toolset) is problematic for me. I would just use a Transform stage and add the RowNumber variable to the MaxValue for each row. The stream would be ready for Insertion to the target table.
I am currently trying to use a Script Component in the Data Flow. Since my VB is rusty, does anyone have a script for incrementing a ReadWrite Variable for insertion to the stream? All I want to do is take the MaxValue and add the RowNumber or increment by 1 each time the script is performed.
If anyone has a simpler method, please let me know. Also, before it starts, yes we are using the Identity feature on the table, however due to processing constraints we need to preassign the Key in our Data Flow. Hence the incrementing of rows....
Cheers.
View 3 Replies
View Related
May 12, 2014
We have a table that has customers invoices and payment records. In some cases a customer has 10 lines with 10 different invoice numbers but may have paid 2 or more invoices with one check. I need to know how many unique payments were made per customer.
Cust# Inv# Chk#
1 109 101
1 110 101
1 111 102
3 112 10003
2 113 799
2 114 800
1 115 103
3 116 10009
2 117 799
1 118 103
So I need the statement to update the customer table with the annual payments
Customer Table
Cust# Payments
1 3
2 2
3 2
I get close but just not getting it to sort itself out.
View 9 Replies
View Related
Mar 21, 2004
Hi
Does anyone know why an error occurs (constraints violated) when I try to have a table with an automated id incrementing by 1. I am uploading the data into the table from dts, so ignore the id field in the dts transformation.
Any ideas or help would really be appreciated, do I need to reference the id field in an activeX script?
Thanks
View 9 Replies
View Related
May 13, 2004
hi am new in this forum and am designind a database in SQLserver and i want to make the primary key auto incremented
can anyone help
View 1 Replies
View Related
May 13, 2004
hi am new in this forum and am designind a database in SQLserver and i want to make the primary key auto incremented
can anyone help
View 2 Replies
View Related
Jun 29, 2004
Hello,
I am making adjustments to a table in my SQL Server Database.
I'm adding a collumn to my database of numeric type.
I wish to write a SQL script that will go through every record in the database and give it a unique number (key) by simply incrementing each number by 1.
I've inherited this database and as you have probably guessed i'm trying to add a primary key to this table as currently there isn't one!
I have no experience what so ever with T-SQL (which I presume i will need to use) as my expertise lie in web development with fairly simple SQL so go easy on me :)
Thanks in advance for your help
View 4 Replies
View Related
Mar 21, 2004
Hi
Does anyone know why an error occurs (constraints violated) when I try to have a table with an automated id incrementing by 1. I am uploading the data into the table from dts, so ignore the id field in the dts transformation.
Any ideas or help would really be appreciated, do I need to reference the id field in an activeX script?
Thanks
View 3 Replies
View Related