[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now


Small Code Problem

Posted on 2004-10-30
Medium Priority
Last Modified: 2013-12-24
I am inserting the entire query just so all the information is there.  The problem at the very end of the code where I have the two UPDATE statements I can't get the value of the 'athleteId' that was selected in the SELECT statement just above.  Basically what is happening is that it is setting the same highschoolID for every single record in the database because athleteid = athleteid for all of them.  I tried using (Where athleteid = qInsert.AthleteID ) but that didn't work.  What should I change?

<cfquery name="qInsert" datasource="CareersSQL">

INSERT INTO CRCathleteAddress (address, address2, city, State, Zip, HomePhone, OtherPhone )
          Values('#Trim(form.address)#', '#Trim(form.address2)#', '#Trim(form.city)#',
          '#Trim(form.state)#', '#Trim(form.zip)#', '#Trim(form.phone)#', '#Trim(form.otherphone)#')


INSERT INTO CRCathlete (firstname, lastname, parent1, parent2, birthday, graddate, gradyear,
          addressID, email, password, gender, sport, ReferredBy)
     Values('#Trim(form.first)#', '#Trim(form.last)#', '#Trim(form.parent1)#',
     '#Trim(form.parent2)#', '#Trim(form.birthday)#', '#Trim(form.graduation)#', '#Trim(form.gradyear)#',
     @lastID, '#Trim(form.email)#', '#Trim(form.password)#', '#Trim(form.gender)#',  '#Trim(form.sport)#',

      FROM CRCathlete
        WHERE addressID = @lastID

INSERT INTO CRCHighSchool (name, phone, address, address2, city, State, Zip)
          Values('#Trim(form.highschool)#', '#Trim(form.hsphone)#', '#Trim(form.hsaddress)#',
          '#Trim(form.hsaddress2)#', '#Trim(form.hscity)#', '#Trim(form.hsstate)#', '#Trim(form.hszip)#')


Update CRCathlete
Set highschoolID = @lastID
WHERE    athleteID = AthleteID

Update CRCathlete
Set  agentid = athleteID + 12000
WHERE    athleteID = AthleteID
Question by:Docjayman
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 21

Accepted Solution

pinaldave earned 300 total points
ID: 12455894
hi that will not work... but as I can see you are very good with SQL.
what youc an do is that... youc an declare another int like
declare @thevar int

how in the select you can do like this
 SELECT (set @thevar = AthleteID)
      FROM CRCathlete
        WHERE addressID = @lastID

I am not good here with code but I am givving you idea...
now when you have to update... do something like this ..

Update CRCathlete
Set highschoolID = @lastID
WHERE    athleteID =@thevar

This does not work when you select in just above...what you will have to do is run the query just above this query then you wil lhave the value... otherwise... till all the results are executed CFQUERY have no answer...

Author Comment

ID: 12457623
I hear ya, I was thinking the same thing, but  I am having a little problem getting the var to equal AthleteID though.  
LVL 21

Expert Comment

ID: 12457648
well then just ask this question in the TA of MSSQL and they will be able to quickly answer your question.

Featured Post

What’s Wrong with Your Cloud Strategy ?

Even as many CIOs are embracing a cloud-first strategy, the reality is that moving to the cloud is a lengthy process and the end-state is likely to be a blend of multiple clouds—public and private. Learn why multicloud solutions matter in this webinar by Nimble Storage.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever sent email via ColdFusion and thought of tracking this mail to capture the exact date and time when the message was opened ?  If yes, then this article is for you ! First we need a table user_email with columns user_id , email , sub…
Most ColdFusion developers get confused between the CFSet, Duplicate, and Structcopy methods of copying a Structure, especially which one to use when. This Article will explain the differences in the approaches with examples; therefore, after readin…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question