Small Code Problem

Posted on 2004-10-30
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(',
          '#Trim(form.state)#', '#Trim(', '#Trim(', '#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(', '#Trim(form.password)#', '#Trim(form.gender)#',  '#Trim(',

      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
    LVL 22

    Accepted Solution

    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

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

    Expert Comment

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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Course: Foundations of Front-End Development

    Jump-start a lucrative career in front-end web development, with zero previous coding experience required. This course covers the basic programming concepts and languages required for creating engaging websites from scratch.

    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…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    This video discusses moving either the default database or any database to a new volume.

    933 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

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now