473,397 Members | 2,056 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Better ID Numbers

I'm sure this has been posted many times, but I never had a need until now.

- I have a DB that tracks engineering jobs.
- Each JOB can have many TASKS.
- I need to track each TASK by a unique ID number in this format:

YYYY - JOB# - TASK#

Each Job number is sequential starting at 1 on January 1st.
Each Task number is sequential starting at 1 with each new JOB.

For example:

2008-37-02 is the 2nd task of the 37th job in the year 2008.

Every new JOB moves starts the task counter back to 1.
Every new YEAR starts the JOB numbers back to 1.

What is the best way to do this?

Thanks!

Peter
Mar 13 '08 #1
3 1260
janders468
112 Expert 100+
I think the best way is to have two tables, a job table and a task table, the job number would be the primary key of the job table and the task number would be the primary key of the task table, the task table should contain a foreign key of the job table ID. You can then add as many related tasks as you need for the associated job table.
Mar 15 '08 #2
ADezii
8,834 Expert 8TB
I'm sure this has been posted many times, but I never had a need until now.

- I have a DB that tracks engineering jobs.
- Each JOB can have many TASKS.
- I need to track each TASK by a unique ID number in this format:

YYYY - JOB# - TASK#

Each Job number is sequential starting at 1 on January 1st.
Each Task number is sequential starting at 1 with each new JOB.

For example:

2008-37-02 is the 2nd task of the 37th job in the year 2008.

Every new JOB moves starts the task counter back to 1.
Every new YEAR starts the JOB numbers back to 1.

What is the best way to do this?

Thanks!

Peter
How do you know when an old job has finished and a new one begun, this is the critical question.
Mar 16 '08 #3
ADezii
8,834 Expert 8TB
I'm sure this has been posted many times, but I never had a need until now.

- I have a DB that tracks engineering jobs.
- Each JOB can have many TASKS.
- I need to track each TASK by a unique ID number in this format:

YYYY - JOB# - TASK#

Each Job number is sequential starting at 1 on January 1st.
Each Task number is sequential starting at 1 with each new JOB.

For example:

2008-37-02 is the 2nd task of the 37th job in the year 2008.

Every new JOB moves starts the task counter back to 1.
Every new YEAR starts the JOB numbers back to 1.

What is the best way to do this?

Thanks!

Peter
The basic logic to generate the next, sequential, TaskID Number, minus the missing critical piece of information listed previously in Post #3 would be something similar to:
Expand|Select|Wrap|Line Numbers
  1. Public Function fGenerateNextTaskID() As String
  2. 'Task ID Format: YYYY-JJ-TT (Year - Job# - Task#)
  3. Dim strLastTaskID As String
  4. Dim intLastTaskIDYear As Integer
  5. Dim intLastTaskIDJobNum As Integer
  6. Dim intLastTaskIDTaskNum As Integer
  7.  
  8. Dim intNextTaskIDYear As Integer
  9. Dim intNextTaskIDJobNum As Integer
  10. Dim intNextTaskIDTaskNum As Integer
  11.  
  12. strLastTaskID = DLast("[TaskID]", "tblTasks")
  13.  
  14. intLastTaskIDYear = Val(Left$(strLastTaskID, 4))
  15. intLastTaskIDJobNum = Val(Mid$(strLastTaskID, 6, 2))
  16. intLastTaskIDTaskNum = Val(Right$(strLastTaskID, 2))
  17.  
  18. If Val(intLastTaskIDYear) = Year(Date) Then             'Not a New Year
  19.   intNextTaskIDYear = intLastTaskIDYear
  20. Else
  21.   intNextTaskIDYear = intLastTaskIDYear + 1             'New Year, increment by 1
  22. End If
  23.  
  24. 'Missing information concerning Job Number
  25. 'If Job Number is the same
  26.   intNextTaskIDJobNum = intLastTaskIDJobNum             'maintain Current Job#
  27.   intNextTaskIDTaskNum = intLastTaskIDTaskNum + 1       'increment Task#
  28. 'Else
  29.   intNextTaskIDJobNum = intLastTaskIDJobNum + 1         'increment Current Job#
  30.   intNextTaskIDTaskNum = 1                              'Reset Task# to 1
  31. 'End If
  32.  
  33. fGenerateNextTaskID = CStr(intNextTaskIDYear) + "-" & Format$(intNextTaskIDJobNum, "00") & _
  34.                       "-" & Format$(intNextTaskIDTaskNum, "00")
  35. End Function
NOTE: This code requires a strick adherence to the TaskID Format of: YYYY-JJ-TT and a seeding of the 1st ID, meaning that you need only a single, manually entered ID, for the code to work.
Mar 16 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

220
by: Brandon J. Van Every | last post by:
What's better about Ruby than Python? I'm sure there's something. What is it? This is not a troll. I'm language shopping and I want people's answers. I don't know beans about Ruby or have...
7
by: david | last post by:
I write a program which returns the maximum of three input integers. both can run weil in the DEV-C++ , but I just wonder which one is better, and I also want to make it clear that if I use the...
8
by: brian.digipimp | last post by:
I turned this in for my programming fundamentals class for our second exam. I am a c++ newb, this is my first class I've taken. I got a good grade on this project I'm just wondering if there is a...
8
by: jquest | last post by:
Hi Again; I have had help from this group before and want to thank everyone, especially PCDatasheet. My database includes a field called HomePhone, it uses the (xxx)xxx-xxx format to include...
36
by: Ben Justice | last post by:
For a program in c, I need some random numbers for a system were people are placing bets. This is not a commerical project btw. Generally, I tend to rely on things from the standard library,...
3
by: darklight | last post by:
Q: write a program so that it excepts six even numbers or until the number 99 is entered please explain why one is better than the other, if that is the case. A1: /*EX6-1.C TO COUNT AND...
5
by: Vidéotron | last post by:
Hi, A bit new to "more complex" expression... So here the case I have: bla bla bla{TPL,some texte or numbers}bla bla bla. I figured out how to write the expression to extract the "{TPL,some...
10
by: weidongtom | last post by:
Hi, I was working on the following problem and I managed to get a solution, but it's too slow. And I am still in search for a better algorithm. Please enlighten me. ...
204
by: Masood | last post by:
I know that this topic may inflame the "C language Taleban", but is there any prospect of some of the neat features of C++ getting incorporated in C? No I am not talking out the OO stuff. I am...
20
by: mike3 | last post by:
Hi. (Xposted to both comp.lang.c++ and comp.programming since I've got questions related to both C++ language and general programming) I've got the following C++ code. The first routine runs in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.