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:
1200+ fellow developers rate and compare features of the top IDEs, like Visual Studio, Eclipse, RAD, Delphi and others, across 13 categories. Enjoy this FREE Download of the IDE User Satisfaction Study by Evans Data Corporation. Download Now!
  #1  
Old September 8th, 2004, 10:10 AM
jgrantham jgrantham is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 6 jgrantham User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Exclamation Newbie

I am new to Coldfusion and am trying to figure out a few things. Please bear with me as I'm under an extreme time crunch here. I have the following query and I want to set the return value to a variable and increase it by 1. What is the best way to do this?

<cfquery name="MaxEvalID" datasource="assoceval">
SELECT DISTINCTROW Max([EvaluationList].[EvaluationID]) AS [EvaluationID]
FROM EvaluationList;
</cfquery>

Thanks for any help and sorry if this question is too easy. I have searched and searched and can't figure it out.

Reply With Quote
  #2  
Old September 8th, 2004, 10:22 AM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,618 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 9 h 44 m 33 sec
Reputation Power: 53
select max(evaluationID) + 1 as evaluationID
from EvaluationList
__________________
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 September 8th, 2004, 10:35 AM
jgrantham jgrantham is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 6 jgrantham User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Exclamation Thanks... ONe More Question though...

What bif the database has no records yet? I want it to get the MAX value, if it exists and return it. If not I want it to set it to "1". How can I do that? This is an AutoNumber field but I can't figure out how to structure my INSERT query to handle this. I figured I would just make it insert a value there. BTW, I didn;t create the DB and am being forced to use it because someone spent "a lot of time on it".

Quote:
Originally Posted by kiteless
select max(evaluationID) + 1 as evaluationID
from EvaluationList

Reply With Quote
  #4  
Old September 8th, 2004, 10:43 AM
jgrantham jgrantham is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 6 jgrantham User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Exclamation Update...

Here is what I have already...

<cfquery name="MaxEvalID" datasource="assoceval">
SELECT Max(EvaluationID) + 1 AS newEvalID
FROM EvaluationList;
</cfquery>

<cfset newEvalID = #MaxEvalID.newEvalID#>

<CFQuery datasource="assoceval">
INSERT INTO EvaluationList VALUES('#MaxEvalID.newEvalID#','#FORM.Evaluated_By#', '#FORM.For#')
</cfquery>

On the INSERT INTO EvaluationList query, it seems to be passing a blank value. Here is the error code:

ODBC Error Code = 22005 (Error in assignment)


[Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression.


SQL = "INSERT INTO EvaluationList VALUES('','99998', '99999')"

Data Source = "ASSOCEVAL"


The error occurred while processing an element with a general identifier of (CFQUERY), occupying document position (9:1) to (9:32) in the template file E:\INTRANET\Associate Eval\confirm.cfm.


Any help would be greatly appreciated!!!

Quote:
Originally Posted by jgrantham
I am new to Coldfusion and am trying to figure out a few things. Please bear with me as I'm under an extreme time crunch here. I have the following query and I want to set the return value to a variable and increase it by 1. What is the best way to do this?

<cfquery name="MaxEvalID" datasource="assoceval">
SELECT DISTINCTROW Max([EvaluationList].[EvaluationID]) AS [EvaluationID]
FROM EvaluationList;
</cfquery>

Thanks for any help and sorry if this question is too easy. I have searched and searched and can't figure it out.

Reply With Quote
  #5  
Old September 8th, 2004, 10:58 AM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,618 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 9 h 44 m 33 sec
Reputation Power: 53
First, if the field is a number you can't put quotes around it in your insert statement. Second, if the field is already an autonumber field then you don't need to select the max id or insert it. The database will automatically populate the field with the next number when you insert a new record:

<CFQuery datasource="assoceval">
INSERT INTO EvaluationList (evaluated_by, for ) VALUES('#FORM.Evaluated_By#', '#FORM.For#')
</cfquery>

Last edited by kiteless : September 8th, 2004 at 11:01 AM.

Reply With Quote
  #6  
Old September 8th, 2004, 11:15 AM
jgrantham jgrantham is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 6 jgrantham User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
It Works!!!!

IT finally works. I guess I just had to hold my tongue just right.

Thanks for all the help.


Quote:
Originally Posted by kiteless
First, if the field is a number you can't put quotes around it in your insert statement. Second, if the field is already an autonumber field then you don't need to select the max id or insert it. The database will automatically populate the field with the next number when you insert a new record:

<CFQuery datasource="assoceval">
INSERT INTO EvaluationList (evaluated_by, for ) VALUES('#FORM.Evaluated_By#', '#FORM.For#')
</cfquery>

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreColdFusion Development > Newbie


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