#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Location
    Minnesota
    Posts
    2
    Rep Power
    0

    SQL statement with 2 parameters


    I'm making a query for a database and want to have 2 having parameters. this first one works but can't get the second one to.

    SELECT Alum.LastName, Alum.FirstName, Alum.Street, Alum.City, Alum.State, Alum.Zipcode, Alum.Country, Alum.Phone, Alum.Email, Alum.Employer, Alum.Title, Alum.WhenGraduated, Alum.DateUpdated, Alum.InitiateNumber, Alum.CompName
    FROM Alum
    GROUP BY Alum.LastName, Alum.FirstName, Alum.Street, Alum.City, Alum.State, Alum.Zipcode, Alum.Country, Alum.Phone, Alum.Email, Alum.Employer, Alum.Title, Alum.WhenGraduated, Alum.DateUpdated, Alum.InitiateNumber, Alum.CompName
    HAVING (((Alum.InitiateNumber)='::inum::'));

    I would like to include Alum.FirstName='::fname::' in the having parameter but it keeps giving me an error. What I'm doing is having the two parameters query a database table and where the 2 equal what is entered, return the data from the record.

    Any suggestions??!!
    Thank you.
  2. #2
  3. Digitally Challenged
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2003
    Posts
    280
    Rep Power
    11
    instead of using HAVING you should be using WHERE because you aren't using a group by clause. so it should look something like this
    Code:
    SELECT Alum.LastName, Alum.FirstName, Alum.Street, Alum.City, Alum.State, Alum.Zipcode, Alum.Country, Alum.Phone, Alum.Email, Alum.Employer, Alum.Title, Alum.WhenGraduated, Alum.DateUpdated, Alum.InitiateNumber, Alum.CompName 
    FROM Alum 
    GROUP BY Alum.LastName, Alum.FirstName, Alum.Street, Alum.City, Alum.State, Alum.Zipcode, Alum.Country, Alum.Phone, Alum.Email, Alum.Employer, Alum.Title, Alum.WhenGraduated, Alum.DateUpdated, Alum.InitiateNumber, Alum.CompName 
    WHERE Alum.InitiateNumber = 1;
    the '1' is just the example number i used. if you want it related to a specific number you'll have to tell me what language you are using to display the data. hope that helps
    My brain cells are like a storm trooper's armor: useless
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Location
    Minnesota
    Posts
    2
    Rep Power
    0
    Thank you, that makes more sense than the way I had it!!
  6. #4
  7. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,026
    Rep Power
    4210
    except that you cannot put WHERE after GROUP BY!!

    furthermore, if you aren't going to use any aggregate functions, then you might as well drop the GROUP BY and use DISTINCT instead

    rudy
    http://r937.com/

IMN logo majestic logo threadwatch logo seochat tools logo