Solved

Small Code Problem

Posted on 2004-10-30
162 Views
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">
DECLARE @lastID INT

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)#')

SET @lastID = SCOPE_IDENTITY()

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)#',
       '#Trim(form.agent)#')

 SELECT AthleteID
      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)#')

SET @lastID = SCOPE_IDENTITY()

Update CRCathlete
Set highschoolID = @lastID
WHERE    athleteID = AthleteID

Update CRCathlete
Set  agentid = athleteID + 12000
WHERE    athleteID = AthleteID
</cfquery>
0
Question by:Docjayman
    3 Comments
     
    LVL 22

    Accepted Solution

    by:
    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...
    Regards,
    ---Pinal
    0
     

    Author Comment

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

    Expert Comment

    by:pinaldave
    well then just ask this question in the TA of MSSQL and they will be able to quickly answer your question.
    Regards,
    ---Pinal
    0

    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