ColdFusion Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreColdFusion Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!
  #1  
Old August 9th, 2004, 01:36 PM
JackSNVC JackSNVC is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 72 JackSNVC User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 29 m 6 sec
Reputation Power: 5
Small problem to Small Problem

hey everyone I have a ? for ya. It probably isnt that hard but here goes. I have a field that is created from 3 different numbers, here is the data in that field :
'#DateFormat(now(),'mmyy')#-#form.projectnumber#-#next_num#'

it would read something like

idnum:
0804-0302-0001

I am trying to find a way for that #next_num# field to populate the field in the table by finding out what the next available autonumber in my num field is...do you understand what I am saying???? I have a column labeled num in the table that is an autonumber but it doesn't autonumber unless you have created the table. But I want it to attach a figure like 0001 onto the idnum column as soon as they submit the form. Also I had the problem of trying to format the numbers from 1 to 0001 and I couldnt figure that out. I tried working w/ CFSET but couldnt get it figured out. Any ideas?

Reply With Quote
  #2  
Old August 9th, 2004, 01:58 PM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,627 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 10 h 8 m 55 sec
Reputation Power: 53
You could select the maximum value of that key, and then just add 1 to it.

Keep in mind though, that if someone else inserts a record in between the time that you select the max value and the time you insert the new record, you'll be using an autonumber value that has already been inserted.
__________________
Ask if you have a question, but also help answer questions that you have knowledge of! Thanks, Brian.
How to Post a Question in the Forums

Reply With Quote
  #3  
Old August 9th, 2004, 02:25 PM
JackSNVC JackSNVC is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 72 JackSNVC User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 29 m 6 sec
Reputation Power: 5
I know it isn't good practice to do this but the user requesting this form stated that there would not be very many users. I understand how to pull max(id) but if I want to use that in an insert into with

#date#-#projectnumber#-#max(num) +1# how would i do that so it would insert that number b/c I am not sure???

also I think to get 0000 format would I use decimalformat(max(num), "0000") or something ilke that right?

Reply With Quote
  #4  
Old August 9th, 2004, 02:56 PM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,627 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 10 h 8 m 55 sec
Reputation Power: 53
You'd have to do two SQL statements. One to select the max ID, and another to insert the new record (and add 1 to the previously selected max id).

You could also look into a nested select statement, but that's more complex.

Reply With Quote
  #5  
Old August 10th, 2004, 10:46 AM
JackSNVC JackSNVC is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 72 JackSNVC User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 29 m 6 sec
Reputation Power: 5
try and try

ok so I think I am close but maybe not let me know if you have any ideas. I keep getting errors but this is the two queries....

<cfquery name="Insert_values" datasource="vacancy">
select max(id) max_num from dbo.vacancy_approved
<cfset next_id = max_num>
</cfquery>

<cfquery name="Insert_values" datasource="vacancy">

insert into dbo.vacancy_approved (idnum, position, programmanager, projectnumber, availability, travel, interview, start_date, type, salary, rate, temp_perm, customer, location, work, clearance, duties, experience, new)

values ('#DateFormat(now(),'mmyy')#-#form.projectnumber#-#decimalformat(next_id)#', '#form.position#', '#form.programmanager#', '#form.projectnumber#', '#form.availability#', '#form.travel#', '#form.interview#', '#form.start_date#', '#form.type#', '#form.salary#', '#form.rate#', '#form.temp_perm#', '#form.customer#', '#form.location#', '#form.work#', '#form.clearance#', '#form.duties#', '#form.experience#', '#form.new#')
</cfquery>

IT TELLS ME THAT MAX_NUM IS UNDEFINED...???

Reply With Quote
  #6  
Old August 10th, 2004, 11:56 AM
JackSNVC JackSNVC is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 72 JackSNVC User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 29 m 6 sec
Reputation Power: 5
I have tried looking through the search engines multiple times for examples but dont see any that really apply for what I am trying to do. I can select the max(num) but I dont see how to insert that value into another cfquery....

Reply With Quote
  #7  
Old August 10th, 2004, 12:19 PM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,627 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 10 h 8 m 55 sec
Reputation Power: 53
In the first query you do something like:

<cfquery name="getMaxID">
select max( ID ) as theMaxID
from myTable
</cfquery>

Then do...

<cfquery name="insertNewRecord">
insert into myTable( ID, firstName, etc... )
values ( #getMaxID.theMaxID + 1#, '#form.firstName#', etc. )
</cfquery>

Reply With Quote
  #8  
Old August 10th, 2004, 12:40 PM
JackSNVC JackSNVC is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 72 JackSNVC User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 29 m 6 sec
Reputation Power: 5
damn kiteless

Kiteless - you da man. Look though, I swear my timing is just great. Right before you did that I figured out how to do it...I learned something today!! Haha. I appreciate your help though. don't get annoyed w/ me I will probably be trying to get a lot of help being that I just started w/ coldfusion.

Jack

Reply With Quote
  #9  
Old August 10th, 2004, 01:18 PM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,627 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 10 h 8 m 55 sec
Reputation Power: 53
The only thing that annoys me is when people ask questions without even trying to solve the problem. In other words, people who just expect others to spit out code for them. Since you did not do that, you have no reason to worry that I'll be annoyed.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreColdFusion Development > Small problem to Small Problem


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway