Some questions:
is the request number unique for each customer and/or for each date? In other words: can we have 2002-11-ABC-0001 and 2002-11-JKL-0001? And can we have 2002-11-ABC-0001 and 2002-12-ABC-0001?
Main Topics
Browse All TopicsOkay I have a table containing my customers. Primary Key is Customer Code, which is usually some three-letter code.
I'd now want to create a Ticket Number for each request logged in by the customers. So the format I'm looking for is something like <Year>-<Month>-<Customer Code>-<Request Number for that customer>, e.g. 2002-11-ABC-0001 or 2002-11-ABD-0002.
How could I do that? Creating new tables is not a problem.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Create a new table called
Ticket_Number
fields are
Customer_Code
Ticket_Number
Primary key is not necessary here.
Store each in its prespective fields
When you want one person and all their tickets
SQL = "SELECT * FROM Customers INNER JOIN Ticket_Number ON Customers.Customer_Code = Ticket_Numbers.Customer_Co
I guess you are going to store these ticket numbers in a table, let's say 'tbl_Tickets'...
For example, customer with code stored in CCode variable requests a new ticket.
'set up everything for your recordset rs....
....
' then:
rs.source = "SELECT * FROM tbl_Tickets WHERE TicketNumber LIKE '" & Year() & "-" & Month() & "-" & CCode & "-%' ORDER BY TicketNumber"
rs.open
Now, skip to last record, strip last four charachters and you have customer's last ticket number for this mounth.
I guess that the number is unique for each customer and each date (i.e. yes for the two questions I asked).
In that case, do the following (which I tried and works):
1) create a table called TICKETS with 4 fields Year, Month, CustomerCode, RequestNumber, where all 4 constitute the primary key (no need for autonumber), and there CustomerCode is a foreing key referencing your table of customers.
2) Queries are extremely simple: if you want to ask for all tickets of october 1999, just do SELECT * FROM TICEKTS WHERE Year=1999 AND Month=10, or all tickets of a specific customer do SELECT * FROM TICKETS WHERE CustomerCode = yourclientcode, etc
3) If you want to create a new ticket after a new request, you simply have to look for the last request number of that specific customer on the same month and same year. The whole code for that would look like this:
To create a Ticket Number for a new request:
<%
Dim conn, rs, sSQL
Dim thisyear, thismonth, thiscustomer, lastRequest
thisyear=Year(Date)
thismonth=Month(Date)
'thiscustomer=Session("cus
thiscustomer="ABC" 'As an example
'Connect to your database the way you usually do it
set conn = Server.CreateObject("ADODB
connectionString = "Provider=Microsoft.Jet.OL
"Data Source=" & server.mappath("mydatabase
conn.open connectionString
'We determine the query string to look for the last request of this customer made this year and this month
sSQL = "SELECT max(RequestNumber) as last_request FROM TICKETS" & _
" WHERE (Year=" & thisyear & " AND Month=" & thismonth & ") AND CustomerCode='" & thiscustomer & "'"
'And we execute it
Set rs = Server.CreateObject("ADODB
rs.CursorType = 0 'ForwardOnly
rs.LockType = 1 'ReadOnly
rs.open sSQL, conn
lastRequest = rs("last_request")
if lastRequest > 0 then
newRequest = lastRequest + 1
else newRequest = 1
end if
'And now just insert the whole in the table
sSQL = "INSERT into TICKETS values (" & thisyear & "," & thismonth & ", '" & thiscustomer & "'," & newRequest & ")"
conn.Execute(sSQL)
rs.Close
set rs = Nothing
conn.close
set conn = Nothing
%>
Hope it helps
Business Accounts
Answer for Membership
by: vintoPosted on 2002-11-07 at 04:52:27ID: 7419422
Some questions:
is the request number unique for each customer and/or for each date? In other words: can we have 2002-11-ABC-0001 and 2002-11-JKL-0001? And can we have 2002-11-ABC-0001 and 2002-12-ABC-0001?