SQL syntax--getting demoralized

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • TomB

    #16
    Re: SQL syntax--getting demoralized

    Can you explain what it is you want returned?
    I'm looking at list.asp right now, and I see a whole bunch of Joe Dirt's at
    the bottom are your 4 combo boxes.

    Are you hoping to limit the number of Joe Dirt's returned to those
    personal's that match the contents of your combos?

    In my database, I've only got 1 Personal and 1 for each of the 4 tables,
    plus an entry for each combination in the join table. This returns one row.

    However, if I add a second ability and add it to the join table as well.
    Then I get two rows returned. I then add a second Area and the join, now I
    have 4 rows returned. All of which makes sense.

    You will still want your IF statements to limit the rows returned (see
    example below).

    Try throwing in a DISTINCT after SELECT ....

    SELECT DISTINCT Personal.FName, Personal.LName, Personal.Prefer redName,
    Personal.Person alID
    FROM (((Personal INNER JOIN PersonalGift ON Personal.Person alID =
    PersonalGift.Pe rsonalID) INNER JOIN PersonalAbility ON Personal.Person alID =
    PersonalAbility .PersonalID) INNER JOIN PersonalPeople ON Personal.Person alID
    = PersonalPeople. PersonalID) INNER JOIN PersonalArea ON Personal.Person alID
    = PersonalArea.Pe rsonalID WHERE PersonalPeople= 1;


    "middletree " <middletree@hto mail.com> wrote in message
    news:u3mrcjg1DH A.2060@TK2MSFTN GP10.phx.gbl...[color=blue]
    > Well, there is good news and bad news. I tried it out (you can, too, just[/color]
    go[color=blue]
    > to www.middletree.net/ then add to the URL: /list.asp
    > (Sorry to break it up like that, but don't want it ending up in Google
    > Groups)
    >
    > Anyway, the good news is, it doesn't throw me an error. Bad news is, it
    > shows 19 rows, every time, no matter what I selected. Thing is, there are
    > only 6 rows in the Personal table!
    >
    >
    >
    > "TomB" <shuckle@hotmai lXXX.com> wrote in message
    > news:um1DrRg1DH A.1704@tk2msftn gp13.phx.gbl...[color=green]
    > > I have a feeling all of those inner joins aren't nesting the way you[/color][/color]
    want[color=blue][color=green]
    > > them to.
    > >
    > > I tried this query in Access and it returned a record if there was a
    > > matching "join" in all of the "union" tables. That is, I created a[/color]
    > Personal[color=green]
    > > item and an item for each of the four other tables, then a join in each[/color][/color]
    of[color=blue][color=green]
    > > the other 4 tables. If any one of the join tables did not contain my
    > > Personal then it didn't show up. I assume that's what you want.
    > >
    > > SELECT Personal.FName, Personal.LName, Personal.Prefer redName,
    > > Personal.Person alID
    > > FROM (((Personal INNER JOIN PersonalGift ON Personal.Person alID =
    > > PersonalGift.Pe rsonalID) INNER JOIN PersonalAbility ON[/color][/color]
    Personal.Person alID[color=blue]
    > =[color=green]
    > > PersonalAbility .PersonalID) INNER JOIN PersonalPeople ON[/color]
    > Personal.Person alID[color=green]
    > > = PersonalPeople. PersonalID) INNER JOIN PersonalArea ON[/color]
    > Personal.Person alID[color=green]
    > > = PersonalArea.Pe rsonalID
    > >
    > > You'll notice I took out the aliases (PersonalAbilit y PAB) I'm not sure[/color][/color]
    if[color=blue][color=green]
    > > they were causing the problem (they shouldn't have been) but I figured[/color][/color]
    I'd[color=blue][color=green]
    > > get them out of the way to be sure.
    > >
    > > So I think the problem is with the parentheses. Adding the where clause
    > > didn't cause a problem.
    > >
    > >
    > > "middletree " <middletree@hto mail.com> wrote in message
    > > news:utggLva1DH A.2388@TK2MSFTN GP09.phx.gbl...[color=darkred]
    > > > I've seen posts here and elsewhere which read something along the[/color][/color][/color]
    lines[color=blue]
    > of[color=green][color=darkred]
    > > > "PULLNG MY HAIR OUT!!!!!" or "HELLLLPPP! ". Well, I know that[/color][/color][/color]
    kind[color=blue]
    > of[color=green][color=darkred]
    > > > subject line isn't descriptive, but I sure can relate right now. I've[/color][/color]
    > been[color=green][color=darkred]
    > > > struggling for days--days!!-- on this one simple query. I really need[/color][/color]
    > to[color=green][color=darkred]
    > > > get past this thing and move on. Please help.
    > > >
    > > > I have a classic ASP page, and it gives you 4 dropdowns. You can[/color][/color][/color]
    select[color=blue][color=green]
    > > any[color=darkred]
    > > > or none of them. Each of them is built by an ACCESS table. These 4[/color][/color]
    > tables[color=green][color=darkred]
    > > > are union tables; they have just 2 fields: the PK from the master[/color][/color][/color]
    table,[color=blue][color=green][color=darkred]
    > > > called Personal, and one of the 4 static tables that I call People,[/color][/color]
    > Area,[color=green][color=darkred]
    > > > Ability, Gift.
    > > >
    > > > Anyway, when someone selects a value from one or more of the[/color][/color][/color]
    dropdowns,[color=blue][color=green]
    > > the[color=darkred]
    > > > next page grabs the values and puts them into variables (strGiftID,
    > > > strAbilityID, strAreaID, and strPeopleID). This is where I am running[/color][/color]
    > into[color=green][color=darkred]
    > > > problems. If you see my previous threads on this, you'll see lots of
    > > > suggestions, and I have tried every one of them.
    > > >
    > > > Here's my current code:
    > > >
    > > > strSQL = "SELECT P.Fname, P.LName, P.PreferredName , P.PersonalID FROM
    > > > Personal P "
    > > > strSQL = strSQL & "INNER JOIN PersonalGift PG ON P.PersonalID =
    > > > PG.PersonalID "
    > > > strSQL = strSQL & "INNER JOIN PersonalArea PA ON P.PersonalID =
    > > > PA.PersonalID "
    > > > strSQL = strSQL & "INNER JOIN PersonalAbility PAB ON P.PersonalID =
    > > > PAB.PersonalID "
    > > > strSQL = strSQL & "INNER JOIN PersonalPeople PP ON P.PersonalID =
    > > > PP.PersonalID "
    > > >
    > > > If strGiftID <> "" Then
    > > > strWhere = "GiftID = "&strGiftID &" AND "
    > > > End if
    > > > If strAreaID <> "" Then
    > > > strWhere = strWhere & "AreaID = "&strAreaID &" AND "
    > > > End if
    > > > If strAbilityID <> "" Then
    > > > strWhere = strWhere & "AbilityID = "&strAbilityID& " AND "
    > > > End if
    > > > If strPeopleID <> "" Then
    > > > strWhere = strWhere & "PeopleID = "&strPeople ID&" AND "
    > > > End if
    > > >
    > > > If Len(strWhere) > 0 Then
    > > > ' Remove the last AND
    > > > strWhere = Left(strWhere, Len(strWhere) - 5)
    > > > strSQL = strSQL & "WHERE " & strWhere
    > > > End If
    > > > ----------------------------------------------
    > > >
    > > > Here's the error:
    > > >
    > > > 'P.PersonalID = PG.PersonalID INNER JOIN PersonalArea PA ON[/color][/color][/color]
    P.PersonalID[color=blue]
    > =[color=green][color=darkred]
    > > > PA.PersonalID INNER JOIN PersonalAbility PAB ON P.PersonalID =
    > > > PAB.PersonalID INNER JOIN PersonalPeople PP ON P.PersonalID =
    > > > PP.PersonalID'.
    > > > /grace/list.asp, line 64
    > > >
    > > > (where line 64 is the line which executes the SQL statement)
    > > >
    > > >
    > > > Please, please let me know what you see that I am doing wrong.
    > > >
    > > > TIA
    > > >
    > > >
    > > >
    > > >
    > > >
    > > >
    > > >
    > > >[/color]
    > >
    > >[/color]
    >
    >[/color]


    Comment

    • middletree

      #17
      Re: SQL syntax--getting demoralized

      For most of your questions, I just answered them in my post to Bob, right
      above yours.

      I added DISTINCT to see what happens, but it now shows 3 users, regardless
      of what was selected.



      "TomB" <shuckle@hotmai lXXX.com> wrote in message
      news:#osPSkh1DH A.3496@TK2MSFTN GP11.phx.gbl...[color=blue]
      > Can you explain what it is you want returned?
      > I'm looking at list.asp right now, and I see a whole bunch of Joe Dirt's[/color]
      at[color=blue]
      > the bottom are your 4 combo boxes.
      >
      > Are you hoping to limit the number of Joe Dirt's returned to those
      > personal's that match the contents of your combos?
      >
      > In my database, I've only got 1 Personal and 1 for each of the 4 tables,
      > plus an entry for each combination in the join table. This returns one[/color]
      row.[color=blue]
      >
      > However, if I add a second ability and add it to the join table as well.
      > Then I get two rows returned. I then add a second Area and the join, now[/color]
      I[color=blue]
      > have 4 rows returned. All of which makes sense.
      >
      > You will still want your IF statements to limit the rows returned (see
      > example below).
      >
      > Try throwing in a DISTINCT after SELECT ....
      >
      > SELECT DISTINCT Personal.FName, Personal.LName, Personal.Prefer redName,
      > Personal.Person alID
      > FROM (((Personal INNER JOIN PersonalGift ON Personal.Person alID =
      > PersonalGift.Pe rsonalID) INNER JOIN PersonalAbility ON Personal.Person alID[/color]
      =[color=blue]
      > PersonalAbility .PersonalID) INNER JOIN PersonalPeople ON[/color]
      Personal.Person alID[color=blue]
      > = PersonalPeople. PersonalID) INNER JOIN PersonalArea ON[/color]
      Personal.Person alID[color=blue]
      > = PersonalArea.Pe rsonalID WHERE PersonalPeople= 1;
      >
      >
      > "middletree " <middletree@hto mail.com> wrote in message
      > news:u3mrcjg1DH A.2060@TK2MSFTN GP10.phx.gbl...[color=green]
      > > Well, there is good news and bad news. I tried it out (you can, too,[/color][/color]
      just[color=blue]
      > go[color=green]
      > > to www.middletree.net/ then add to the URL: /list.asp
      > > (Sorry to break it up like that, but don't want it ending up in Google
      > > Groups)
      > >
      > > Anyway, the good news is, it doesn't throw me an error. Bad news is, it
      > > shows 19 rows, every time, no matter what I selected. Thing is, there[/color][/color]
      are[color=blue][color=green]
      > > only 6 rows in the Personal table!
      > >
      > >
      > >
      > > "TomB" <shuckle@hotmai lXXX.com> wrote in message
      > > news:um1DrRg1DH A.1704@tk2msftn gp13.phx.gbl...[color=darkred]
      > > > I have a feeling all of those inner joins aren't nesting the way you[/color][/color]
      > want[color=green][color=darkred]
      > > > them to.
      > > >
      > > > I tried this query in Access and it returned a record if there was a
      > > > matching "join" in all of the "union" tables. That is, I created a[/color]
      > > Personal[color=darkred]
      > > > item and an item for each of the four other tables, then a join in[/color][/color][/color]
      each[color=blue]
      > of[color=green][color=darkred]
      > > > the other 4 tables. If any one of the join tables did not contain my
      > > > Personal then it didn't show up. I assume that's what you want.
      > > >
      > > > SELECT Personal.FName, Personal.LName, Personal.Prefer redName,
      > > > Personal.Person alID
      > > > FROM (((Personal INNER JOIN PersonalGift ON Personal.Person alID =
      > > > PersonalGift.Pe rsonalID) INNER JOIN PersonalAbility ON[/color][/color]
      > Personal.Person alID[color=green]
      > > =[color=darkred]
      > > > PersonalAbility .PersonalID) INNER JOIN PersonalPeople ON[/color]
      > > Personal.Person alID[color=darkred]
      > > > = PersonalPeople. PersonalID) INNER JOIN PersonalArea ON[/color]
      > > Personal.Person alID[color=darkred]
      > > > = PersonalArea.Pe rsonalID
      > > >
      > > > You'll notice I took out the aliases (PersonalAbilit y PAB) I'm not[/color][/color][/color]
      sure[color=blue]
      > if[color=green][color=darkred]
      > > > they were causing the problem (they shouldn't have been) but I figured[/color][/color]
      > I'd[color=green][color=darkred]
      > > > get them out of the way to be sure.
      > > >
      > > > So I think the problem is with the parentheses. Adding the where[/color][/color][/color]
      clause[color=blue][color=green][color=darkred]
      > > > didn't cause a problem.
      > > >
      > > >
      > > > "middletree " <middletree@hto mail.com> wrote in message
      > > > news:utggLva1DH A.2388@TK2MSFTN GP09.phx.gbl...
      > > > > I've seen posts here and elsewhere which read something along the[/color][/color]
      > lines[color=green]
      > > of[color=darkred]
      > > > > "PULLNG MY HAIR OUT!!!!!" or "HELLLLPPP! ". Well, I know that[/color][/color]
      > kind[color=green]
      > > of[color=darkred]
      > > > > subject line isn't descriptive, but I sure can relate right now.[/color][/color][/color]
      I've[color=blue][color=green]
      > > been[color=darkred]
      > > > > struggling for days--days!!-- on this one simple query. I really[/color][/color][/color]
      need[color=blue][color=green]
      > > to[color=darkred]
      > > > > get past this thing and move on. Please help.
      > > > >
      > > > > I have a classic ASP page, and it gives you 4 dropdowns. You can[/color][/color]
      > select[color=green][color=darkred]
      > > > any
      > > > > or none of them. Each of them is built by an ACCESS table. These 4[/color]
      > > tables[color=darkred]
      > > > > are union tables; they have just 2 fields: the PK from the master[/color][/color]
      > table,[color=green][color=darkred]
      > > > > called Personal, and one of the 4 static tables that I call People,[/color]
      > > Area,[color=darkred]
      > > > > Ability, Gift.
      > > > >
      > > > > Anyway, when someone selects a value from one or more of the[/color][/color]
      > dropdowns,[color=green][color=darkred]
      > > > the
      > > > > next page grabs the values and puts them into variables (strGiftID,
      > > > > strAbilityID, strAreaID, and strPeopleID). This is where I am[/color][/color][/color]
      running[color=blue][color=green]
      > > into[color=darkred]
      > > > > problems. If you see my previous threads on this, you'll see lots of
      > > > > suggestions, and I have tried every one of them.
      > > > >
      > > > > Here's my current code:
      > > > >
      > > > > strSQL = "SELECT P.Fname, P.LName, P.PreferredName , P.PersonalID[/color][/color][/color]
      FROM[color=blue][color=green][color=darkred]
      > > > > Personal P "
      > > > > strSQL = strSQL & "INNER JOIN PersonalGift PG ON P.PersonalID =
      > > > > PG.PersonalID "
      > > > > strSQL = strSQL & "INNER JOIN PersonalArea PA ON P.PersonalID =
      > > > > PA.PersonalID "
      > > > > strSQL = strSQL & "INNER JOIN PersonalAbility PAB ON P.PersonalID =
      > > > > PAB.PersonalID "
      > > > > strSQL = strSQL & "INNER JOIN PersonalPeople PP ON P.PersonalID =
      > > > > PP.PersonalID "
      > > > >
      > > > > If strGiftID <> "" Then
      > > > > strWhere = "GiftID = "&strGiftID &" AND "
      > > > > End if
      > > > > If strAreaID <> "" Then
      > > > > strWhere = strWhere & "AreaID = "&strAreaID &" AND "
      > > > > End if
      > > > > If strAbilityID <> "" Then
      > > > > strWhere = strWhere & "AbilityID = "&strAbilityID& " AND "
      > > > > End if
      > > > > If strPeopleID <> "" Then
      > > > > strWhere = strWhere & "PeopleID = "&strPeople ID&" AND "
      > > > > End if
      > > > >
      > > > > If Len(strWhere) > 0 Then
      > > > > ' Remove the last AND
      > > > > strWhere = Left(strWhere, Len(strWhere) - 5)
      > > > > strSQL = strSQL & "WHERE " & strWhere
      > > > > End If
      > > > > ----------------------------------------------
      > > > >
      > > > > Here's the error:
      > > > >
      > > > > 'P.PersonalID = PG.PersonalID INNER JOIN PersonalArea PA ON[/color][/color]
      > P.PersonalID[color=green]
      > > =[color=darkred]
      > > > > PA.PersonalID INNER JOIN PersonalAbility PAB ON P.PersonalID =
      > > > > PAB.PersonalID INNER JOIN PersonalPeople PP ON P.PersonalID =
      > > > > PP.PersonalID'.
      > > > > /grace/list.asp, line 64
      > > > >
      > > > > (where line 64 is the line which executes the SQL statement)
      > > > >
      > > > >
      > > > > Please, please let me know what you see that I am doing wrong.
      > > > >
      > > > > TIA
      > > > >
      > > > >
      > > > >
      > > > >
      > > > >
      > > > >
      > > > >
      > > > >
      > > >
      > > >[/color]
      > >
      > >[/color]
      >
      >[/color]


      Comment

      • TomB

        #18
        Re: SQL syntax--getting demoralized

        Yes, but if you run that in Access, you'll see that your three records are
        all DISTINCT.
        1. Joe Dirt PersonalID=215
        2. Joe Dirt PersonalID=217
        3. joe Doe PersonalID=218

        "middletree " <middletree@hto mail.com> wrote in message
        news:uC4Rkph1DH A.208@TK2MSFTNG P12.phx.gbl...[color=blue]
        > For most of your questions, I just answered them in my post to Bob, right
        > above yours.
        >
        > I added DISTINCT to see what happens, but it now shows 3 users, regardless
        > of what was selected.
        >
        >
        >
        > "TomB" <shuckle@hotmai lXXX.com> wrote in message
        > news:#osPSkh1DH A.3496@TK2MSFTN GP11.phx.gbl...[color=green]
        > > Can you explain what it is you want returned?
        > > I'm looking at list.asp right now, and I see a whole bunch of Joe Dirt's[/color]
        > at[color=green]
        > > the bottom are your 4 combo boxes.
        > >
        > > Are you hoping to limit the number of Joe Dirt's returned to those
        > > personal's that match the contents of your combos?
        > >
        > > In my database, I've only got 1 Personal and 1 for each of the 4 tables,
        > > plus an entry for each combination in the join table. This returns one[/color]
        > row.[color=green]
        > >
        > > However, if I add a second ability and add it to the join table as well.
        > > Then I get two rows returned. I then add a second Area and the join,[/color][/color]
        now[color=blue]
        > I[color=green]
        > > have 4 rows returned. All of which makes sense.
        > >
        > > You will still want your IF statements to limit the rows returned (see
        > > example below).
        > >
        > > Try throwing in a DISTINCT after SELECT ....
        > >
        > > SELECT DISTINCT Personal.FName, Personal.LName, Personal.Prefer redName,
        > > Personal.Person alID
        > > FROM (((Personal INNER JOIN PersonalGift ON Personal.Person alID =
        > > PersonalGift.Pe rsonalID) INNER JOIN PersonalAbility ON[/color][/color]
        Personal.Person alID[color=blue]
        > =[color=green]
        > > PersonalAbility .PersonalID) INNER JOIN PersonalPeople ON[/color]
        > Personal.Person alID[color=green]
        > > = PersonalPeople. PersonalID) INNER JOIN PersonalArea ON[/color]
        > Personal.Person alID[color=green]
        > > = PersonalArea.Pe rsonalID WHERE PersonalPeople= 1;
        > >
        > >
        > > "middletree " <middletree@hto mail.com> wrote in message
        > > news:u3mrcjg1DH A.2060@TK2MSFTN GP10.phx.gbl...[color=darkred]
        > > > Well, there is good news and bad news. I tried it out (you can, too,[/color][/color]
        > just[color=green]
        > > go[color=darkred]
        > > > to www.middletree.net/ then add to the URL: /list.asp
        > > > (Sorry to break it up like that, but don't want it ending up in Google
        > > > Groups)
        > > >
        > > > Anyway, the good news is, it doesn't throw me an error. Bad news is,[/color][/color][/color]
        it[color=blue][color=green][color=darkred]
        > > > shows 19 rows, every time, no matter what I selected. Thing is, there[/color][/color]
        > are[color=green][color=darkred]
        > > > only 6 rows in the Personal table!
        > > >
        > > >
        > > >
        > > > "TomB" <shuckle@hotmai lXXX.com> wrote in message
        > > > news:um1DrRg1DH A.1704@tk2msftn gp13.phx.gbl...
        > > > > I have a feeling all of those inner joins aren't nesting the way you[/color]
        > > want[color=darkred]
        > > > > them to.
        > > > >
        > > > > I tried this query in Access and it returned a record if there was a
        > > > > matching "join" in all of the "union" tables. That is, I created a
        > > > Personal
        > > > > item and an item for each of the four other tables, then a join in[/color][/color]
        > each[color=green]
        > > of[color=darkred]
        > > > > the other 4 tables. If any one of the join tables did not contain[/color][/color][/color]
        my[color=blue][color=green][color=darkred]
        > > > > Personal then it didn't show up. I assume that's what you want.
        > > > >
        > > > > SELECT Personal.FName, Personal.LName, Personal.Prefer redName,
        > > > > Personal.Person alID
        > > > > FROM (((Personal INNER JOIN PersonalGift ON Personal.Person alID =
        > > > > PersonalGift.Pe rsonalID) INNER JOIN PersonalAbility ON[/color]
        > > Personal.Person alID[color=darkred]
        > > > =
        > > > > PersonalAbility .PersonalID) INNER JOIN PersonalPeople ON
        > > > Personal.Person alID
        > > > > = PersonalPeople. PersonalID) INNER JOIN PersonalArea ON
        > > > Personal.Person alID
        > > > > = PersonalArea.Pe rsonalID
        > > > >
        > > > > You'll notice I took out the aliases (PersonalAbilit y PAB) I'm not[/color][/color]
        > sure[color=green]
        > > if[color=darkred]
        > > > > they were causing the problem (they shouldn't have been) but I[/color][/color][/color]
        figured[color=blue][color=green]
        > > I'd[color=darkred]
        > > > > get them out of the way to be sure.
        > > > >
        > > > > So I think the problem is with the parentheses. Adding the where[/color][/color]
        > clause[color=green][color=darkred]
        > > > > didn't cause a problem.
        > > > >
        > > > >
        > > > > "middletree " <middletree@hto mail.com> wrote in message
        > > > > news:utggLva1DH A.2388@TK2MSFTN GP09.phx.gbl...
        > > > > > I've seen posts here and elsewhere which read something along the[/color]
        > > lines[color=darkred]
        > > > of
        > > > > > "PULLNG MY HAIR OUT!!!!!" or "HELLLLPPP! ". Well, I know that[/color]
        > > kind[color=darkred]
        > > > of
        > > > > > subject line isn't descriptive, but I sure can relate right now.[/color][/color]
        > I've[color=green][color=darkred]
        > > > been
        > > > > > struggling for days--days!!-- on this one simple query. I really[/color][/color]
        > need[color=green][color=darkred]
        > > > to
        > > > > > get past this thing and move on. Please help.
        > > > > >
        > > > > > I have a classic ASP page, and it gives you 4 dropdowns. You can[/color]
        > > select[color=darkred]
        > > > > any
        > > > > > or none of them. Each of them is built by an ACCESS table. These 4
        > > > tables
        > > > > > are union tables; they have just 2 fields: the PK from the master[/color]
        > > table,[color=darkred]
        > > > > > called Personal, and one of the 4 static tables that I call[/color][/color][/color]
        People,[color=blue][color=green][color=darkred]
        > > > Area,
        > > > > > Ability, Gift.
        > > > > >
        > > > > > Anyway, when someone selects a value from one or more of the[/color]
        > > dropdowns,[color=darkred]
        > > > > the
        > > > > > next page grabs the values and puts them into variables[/color][/color][/color]
        (strGiftID,[color=blue][color=green][color=darkred]
        > > > > > strAbilityID, strAreaID, and strPeopleID). This is where I am[/color][/color]
        > running[color=green][color=darkred]
        > > > into
        > > > > > problems. If you see my previous threads on this, you'll see lots[/color][/color][/color]
        of[color=blue][color=green][color=darkred]
        > > > > > suggestions, and I have tried every one of them.
        > > > > >
        > > > > > Here's my current code:
        > > > > >
        > > > > > strSQL = "SELECT P.Fname, P.LName, P.PreferredName , P.PersonalID[/color][/color]
        > FROM[color=green][color=darkred]
        > > > > > Personal P "
        > > > > > strSQL = strSQL & "INNER JOIN PersonalGift PG ON P.PersonalID =
        > > > > > PG.PersonalID "
        > > > > > strSQL = strSQL & "INNER JOIN PersonalArea PA ON P.PersonalID =
        > > > > > PA.PersonalID "
        > > > > > strSQL = strSQL & "INNER JOIN PersonalAbility PAB ON P.PersonalID[/color][/color][/color]
        =[color=blue][color=green][color=darkred]
        > > > > > PAB.PersonalID "
        > > > > > strSQL = strSQL & "INNER JOIN PersonalPeople PP ON P.PersonalID =
        > > > > > PP.PersonalID "
        > > > > >
        > > > > > If strGiftID <> "" Then
        > > > > > strWhere = "GiftID = "&strGiftID &" AND "
        > > > > > End if
        > > > > > If strAreaID <> "" Then
        > > > > > strWhere = strWhere & "AreaID = "&strAreaID &" AND "
        > > > > > End if
        > > > > > If strAbilityID <> "" Then
        > > > > > strWhere = strWhere & "AbilityID = "&strAbilityID& " AND "
        > > > > > End if
        > > > > > If strPeopleID <> "" Then
        > > > > > strWhere = strWhere & "PeopleID = "&strPeople ID&" AND "
        > > > > > End if
        > > > > >
        > > > > > If Len(strWhere) > 0 Then
        > > > > > ' Remove the last AND
        > > > > > strWhere = Left(strWhere, Len(strWhere) - 5)
        > > > > > strSQL = strSQL & "WHERE " & strWhere
        > > > > > End If
        > > > > > ----------------------------------------------
        > > > > >
        > > > > > Here's the error:
        > > > > >
        > > > > > 'P.PersonalID = PG.PersonalID INNER JOIN PersonalArea PA ON[/color]
        > > P.PersonalID[color=darkred]
        > > > =
        > > > > > PA.PersonalID INNER JOIN PersonalAbility PAB ON P.PersonalID =
        > > > > > PAB.PersonalID INNER JOIN PersonalPeople PP ON P.PersonalID =
        > > > > > PP.PersonalID'.
        > > > > > /grace/list.asp, line 64
        > > > > >
        > > > > > (where line 64 is the line which executes the SQL statement)
        > > > > >
        > > > > >
        > > > > > Please, please let me know what you see that I am doing wrong.
        > > > > >
        > > > > > TIA
        > > > > >
        > > > > >
        > > > > >
        > > > > >
        > > > > >
        > > > > >
        > > > > >
        > > > > >
        > > > >
        > > > >
        > > >
        > > >[/color]
        > >
        > >[/color]
        >
        >[/color]


        Comment

        • middletree

          #19
          Re: SQL syntax--getting demoralized

          Yes, I understand that. That definitely solves part of the problem. I'm
          glad you caught that.


          "TomB" <shuckle@hotmai lXXX.com> wrote in message
          news:#LE0zuh1DH A.1508@TK2MSFTN GP12.phx.gbl...[color=blue]
          > Yes, but if you run that in Access, you'll see that your three records are
          > all DISTINCT.
          > 1. Joe Dirt PersonalID=215
          > 2. Joe Dirt PersonalID=217
          > 3. joe Doe PersonalID=218
          >
          > "middletree " <middletree@hto mail.com> wrote in message
          > news:uC4Rkph1DH A.208@TK2MSFTNG P12.phx.gbl...[color=green]
          > > For most of your questions, I just answered them in my post to Bob,[/color][/color]
          right[color=blue][color=green]
          > > above yours.
          > >
          > > I added DISTINCT to see what happens, but it now shows 3 users,[/color][/color]
          regardless[color=blue][color=green]
          > > of what was selected.
          > >
          > >
          > >
          > > "TomB" <shuckle@hotmai lXXX.com> wrote in message
          > > news:#osPSkh1DH A.3496@TK2MSFTN GP11.phx.gbl...[color=darkred]
          > > > Can you explain what it is you want returned?
          > > > I'm looking at list.asp right now, and I see a whole bunch of Joe[/color][/color][/color]
          Dirt's[color=blue][color=green]
          > > at[color=darkred]
          > > > the bottom are your 4 combo boxes.
          > > >
          > > > Are you hoping to limit the number of Joe Dirt's returned to those
          > > > personal's that match the contents of your combos?
          > > >
          > > > In my database, I've only got 1 Personal and 1 for each of the 4[/color][/color][/color]
          tables,[color=blue][color=green][color=darkred]
          > > > plus an entry for each combination in the join table. This returns[/color][/color][/color]
          one[color=blue][color=green]
          > > row.[color=darkred]
          > > >
          > > > However, if I add a second ability and add it to the join table as[/color][/color][/color]
          well.[color=blue][color=green][color=darkred]
          > > > Then I get two rows returned. I then add a second Area and the join,[/color][/color]
          > now[color=green]
          > > I[color=darkred]
          > > > have 4 rows returned. All of which makes sense.
          > > >
          > > > You will still want your IF statements to limit the rows returned (see
          > > > example below).
          > > >
          > > > Try throwing in a DISTINCT after SELECT ....
          > > >
          > > > SELECT DISTINCT Personal.FName, Personal.LName,[/color][/color][/color]
          Personal.Prefer redName,[color=blue][color=green][color=darkred]
          > > > Personal.Person alID
          > > > FROM (((Personal INNER JOIN PersonalGift ON Personal.Person alID =
          > > > PersonalGift.Pe rsonalID) INNER JOIN PersonalAbility ON[/color][/color]
          > Personal.Person alID[color=green]
          > > =[color=darkred]
          > > > PersonalAbility .PersonalID) INNER JOIN PersonalPeople ON[/color]
          > > Personal.Person alID[color=darkred]
          > > > = PersonalPeople. PersonalID) INNER JOIN PersonalArea ON[/color]
          > > Personal.Person alID[color=darkred]
          > > > = PersonalArea.Pe rsonalID WHERE PersonalPeople= 1;
          > > >
          > > >
          > > > "middletree " <middletree@hto mail.com> wrote in message
          > > > news:u3mrcjg1DH A.2060@TK2MSFTN GP10.phx.gbl...
          > > > > Well, there is good news and bad news. I tried it out (you can, too,[/color]
          > > just[color=darkred]
          > > > go
          > > > > to www.middletree.net/ then add to the URL: /list.asp
          > > > > (Sorry to break it up like that, but don't want it ending up in[/color][/color][/color]
          Google[color=blue][color=green][color=darkred]
          > > > > Groups)
          > > > >
          > > > > Anyway, the good news is, it doesn't throw me an error. Bad news is,[/color][/color]
          > it[color=green][color=darkred]
          > > > > shows 19 rows, every time, no matter what I selected. Thing is,[/color][/color][/color]
          there[color=blue][color=green]
          > > are[color=darkred]
          > > > > only 6 rows in the Personal table!
          > > > >
          > > > >
          > > > >
          > > > > "TomB" <shuckle@hotmai lXXX.com> wrote in message
          > > > > news:um1DrRg1DH A.1704@tk2msftn gp13.phx.gbl...
          > > > > > I have a feeling all of those inner joins aren't nesting the way[/color][/color][/color]
          you[color=blue][color=green][color=darkred]
          > > > want
          > > > > > them to.
          > > > > >
          > > > > > I tried this query in Access and it returned a record if there was[/color][/color][/color]
          a[color=blue][color=green][color=darkred]
          > > > > > matching "join" in all of the "union" tables. That is, I created[/color][/color][/color]
          a[color=blue][color=green][color=darkred]
          > > > > Personal
          > > > > > item and an item for each of the four other tables, then a join in[/color]
          > > each[color=darkred]
          > > > of
          > > > > > the other 4 tables. If any one of the join tables did not contain[/color][/color]
          > my[color=green][color=darkred]
          > > > > > Personal then it didn't show up. I assume that's what you want.
          > > > > >
          > > > > > SELECT Personal.FName, Personal.LName, Personal.Prefer redName,
          > > > > > Personal.Person alID
          > > > > > FROM (((Personal INNER JOIN PersonalGift ON Personal.Person alID =
          > > > > > PersonalGift.Pe rsonalID) INNER JOIN PersonalAbility ON
          > > > Personal.Person alID
          > > > > =
          > > > > > PersonalAbility .PersonalID) INNER JOIN PersonalPeople ON
          > > > > Personal.Person alID
          > > > > > = PersonalPeople. PersonalID) INNER JOIN PersonalArea ON
          > > > > Personal.Person alID
          > > > > > = PersonalArea.Pe rsonalID
          > > > > >
          > > > > > You'll notice I took out the aliases (PersonalAbilit y PAB) I'm not[/color]
          > > sure[color=darkred]
          > > > if
          > > > > > they were causing the problem (they shouldn't have been) but I[/color][/color]
          > figured[color=green][color=darkred]
          > > > I'd
          > > > > > get them out of the way to be sure.
          > > > > >
          > > > > > So I think the problem is with the parentheses. Adding the where[/color]
          > > clause[color=darkred]
          > > > > > didn't cause a problem.
          > > > > >
          > > > > >
          > > > > > "middletree " <middletree@hto mail.com> wrote in message
          > > > > > news:utggLva1DH A.2388@TK2MSFTN GP09.phx.gbl...
          > > > > > > I've seen posts here and elsewhere which read something along[/color][/color][/color]
          the[color=blue][color=green][color=darkred]
          > > > lines
          > > > > of
          > > > > > > "PULLNG MY HAIR OUT!!!!!" or "HELLLLPPP! ". Well, I know[/color][/color][/color]
          that[color=blue][color=green][color=darkred]
          > > > kind
          > > > > of
          > > > > > > subject line isn't descriptive, but I sure can relate right now.[/color]
          > > I've[color=darkred]
          > > > > been
          > > > > > > struggling for days--days!!-- on this one simple query. I[/color][/color][/color]
          really[color=blue][color=green]
          > > need[color=darkred]
          > > > > to
          > > > > > > get past this thing and move on. Please help.
          > > > > > >
          > > > > > > I have a classic ASP page, and it gives you 4 dropdowns. You can
          > > > select
          > > > > > any
          > > > > > > or none of them. Each of them is built by an ACCESS table. These[/color][/color][/color]
          4[color=blue][color=green][color=darkred]
          > > > > tables
          > > > > > > are union tables; they have just 2 fields: the PK from the[/color][/color][/color]
          master[color=blue][color=green][color=darkred]
          > > > table,
          > > > > > > called Personal, and one of the 4 static tables that I call[/color][/color]
          > People,[color=green][color=darkred]
          > > > > Area,
          > > > > > > Ability, Gift.
          > > > > > >
          > > > > > > Anyway, when someone selects a value from one or more of the
          > > > dropdowns,
          > > > > > the
          > > > > > > next page grabs the values and puts them into variables[/color][/color]
          > (strGiftID,[color=green][color=darkred]
          > > > > > > strAbilityID, strAreaID, and strPeopleID). This is where I am[/color]
          > > running[color=darkred]
          > > > > into
          > > > > > > problems. If you see my previous threads on this, you'll see[/color][/color][/color]
          lots[color=blue]
          > of[color=green][color=darkred]
          > > > > > > suggestions, and I have tried every one of them.
          > > > > > >
          > > > > > > Here's my current code:
          > > > > > >
          > > > > > > strSQL = "SELECT P.Fname, P.LName, P.PreferredName , P.PersonalID[/color]
          > > FROM[color=darkred]
          > > > > > > Personal P "
          > > > > > > strSQL = strSQL & "INNER JOIN PersonalGift PG ON P.PersonalID =
          > > > > > > PG.PersonalID "
          > > > > > > strSQL = strSQL & "INNER JOIN PersonalArea PA ON P.PersonalID =
          > > > > > > PA.PersonalID "
          > > > > > > strSQL = strSQL & "INNER JOIN PersonalAbility PAB ON[/color][/color][/color]
          P.PersonalID[color=blue]
          > =[color=green][color=darkred]
          > > > > > > PAB.PersonalID "
          > > > > > > strSQL = strSQL & "INNER JOIN PersonalPeople PP ON P.PersonalID[/color][/color][/color]
          =[color=blue][color=green][color=darkred]
          > > > > > > PP.PersonalID "
          > > > > > >
          > > > > > > If strGiftID <> "" Then
          > > > > > > strWhere = "GiftID = "&strGiftID &" AND "
          > > > > > > End if
          > > > > > > If strAreaID <> "" Then
          > > > > > > strWhere = strWhere & "AreaID = "&strAreaID &" AND "
          > > > > > > End if
          > > > > > > If strAbilityID <> "" Then
          > > > > > > strWhere = strWhere & "AbilityID = "&strAbilityID& " AND "
          > > > > > > End if
          > > > > > > If strPeopleID <> "" Then
          > > > > > > strWhere = strWhere & "PeopleID = "&strPeople ID&" AND "
          > > > > > > End if
          > > > > > >
          > > > > > > If Len(strWhere) > 0 Then
          > > > > > > ' Remove the last AND
          > > > > > > strWhere = Left(strWhere, Len(strWhere) - 5)
          > > > > > > strSQL = strSQL & "WHERE " & strWhere
          > > > > > > End If
          > > > > > > ----------------------------------------------
          > > > > > >
          > > > > > > Here's the error:
          > > > > > >
          > > > > > > 'P.PersonalID = PG.PersonalID INNER JOIN PersonalArea PA ON
          > > > P.PersonalID
          > > > > =
          > > > > > > PA.PersonalID INNER JOIN PersonalAbility PAB ON P.PersonalID =
          > > > > > > PAB.PersonalID INNER JOIN PersonalPeople PP ON P.PersonalID =
          > > > > > > PP.PersonalID'.
          > > > > > > /grace/list.asp, line 64
          > > > > > >
          > > > > > > (where line 64 is the line which executes the SQL statement)
          > > > > > >
          > > > > > >
          > > > > > > Please, please let me know what you see that I am doing wrong.
          > > > > > >
          > > > > > > TIA
          > > > > > >
          > > > > > >
          > > > > > >
          > > > > > >
          > > > > > >
          > > > > > >
          > > > > > >
          > > > > > >
          > > > > >
          > > > > >
          > > > >
          > > > >
          > > >
          > > >[/color]
          > >
          > >[/color]
          >
          >[/color]


          Comment

          • TomB

            #20
            Re: SQL syntax--getting demoralized

            Now you need to put your IFs back in there to limit the results.

            "middletree " <middletree@hto mail.com> wrote in message
            news:uqyqh0h1DH A.1704@tk2msftn gp13.phx.gbl...[color=blue]
            > Yes, I understand that. That definitely solves part of the problem. I'm
            > glad you caught that.
            >
            >
            > "TomB" <shuckle@hotmai lXXX.com> wrote in message
            > news:#LE0zuh1DH A.1508@TK2MSFTN GP12.phx.gbl...[color=green]
            > > Yes, but if you run that in Access, you'll see that your three records[/color][/color]
            are[color=blue][color=green]
            > > all DISTINCT.
            > > 1. Joe Dirt PersonalID=215
            > > 2. Joe Dirt PersonalID=217
            > > 3. joe Doe PersonalID=218
            > >
            > > "middletree " <middletree@hto mail.com> wrote in message
            > > news:uC4Rkph1DH A.208@TK2MSFTNG P12.phx.gbl...[color=darkred]
            > > > For most of your questions, I just answered them in my post to Bob,[/color][/color]
            > right[color=green][color=darkred]
            > > > above yours.
            > > >
            > > > I added DISTINCT to see what happens, but it now shows 3 users,[/color][/color]
            > regardless[color=green][color=darkred]
            > > > of what was selected.
            > > >
            > > >
            > > >
            > > > "TomB" <shuckle@hotmai lXXX.com> wrote in message
            > > > news:#osPSkh1DH A.3496@TK2MSFTN GP11.phx.gbl...
            > > > > Can you explain what it is you want returned?
            > > > > I'm looking at list.asp right now, and I see a whole bunch of Joe[/color][/color]
            > Dirt's[color=green][color=darkred]
            > > > at
            > > > > the bottom are your 4 combo boxes.
            > > > >
            > > > > Are you hoping to limit the number of Joe Dirt's returned to those
            > > > > personal's that match the contents of your combos?
            > > > >
            > > > > In my database, I've only got 1 Personal and 1 for each of the 4[/color][/color]
            > tables,[color=green][color=darkred]
            > > > > plus an entry for each combination in the join table. This returns[/color][/color]
            > one[color=green][color=darkred]
            > > > row.
            > > > >
            > > > > However, if I add a second ability and add it to the join table as[/color][/color]
            > well.[color=green][color=darkred]
            > > > > Then I get two rows returned. I then add a second Area and the[/color][/color][/color]
            join,[color=blue][color=green]
            > > now[color=darkred]
            > > > I
            > > > > have 4 rows returned. All of which makes sense.
            > > > >
            > > > > You will still want your IF statements to limit the rows returned[/color][/color][/color]
            (see[color=blue][color=green][color=darkred]
            > > > > example below).
            > > > >
            > > > > Try throwing in a DISTINCT after SELECT ....
            > > > >
            > > > > SELECT DISTINCT Personal.FName, Personal.LName,[/color][/color]
            > Personal.Prefer redName,[color=green][color=darkred]
            > > > > Personal.Person alID
            > > > > FROM (((Personal INNER JOIN PersonalGift ON Personal.Person alID =
            > > > > PersonalGift.Pe rsonalID) INNER JOIN PersonalAbility ON[/color]
            > > Personal.Person alID[color=darkred]
            > > > =
            > > > > PersonalAbility .PersonalID) INNER JOIN PersonalPeople ON
            > > > Personal.Person alID
            > > > > = PersonalPeople. PersonalID) INNER JOIN PersonalArea ON
            > > > Personal.Person alID
            > > > > = PersonalArea.Pe rsonalID WHERE PersonalPeople= 1;
            > > > >
            > > > >
            > > > > "middletree " <middletree@hto mail.com> wrote in message
            > > > > news:u3mrcjg1DH A.2060@TK2MSFTN GP10.phx.gbl...
            > > > > > Well, there is good news and bad news. I tried it out (you can,[/color][/color][/color]
            too,[color=blue][color=green][color=darkred]
            > > > just
            > > > > go
            > > > > > to www.middletree.net/ then add to the URL: /list.asp
            > > > > > (Sorry to break it up like that, but don't want it ending up in[/color][/color]
            > Google[color=green][color=darkred]
            > > > > > Groups)
            > > > > >
            > > > > > Anyway, the good news is, it doesn't throw me an error. Bad news[/color][/color][/color]
            is,[color=blue][color=green]
            > > it[color=darkred]
            > > > > > shows 19 rows, every time, no matter what I selected. Thing is,[/color][/color]
            > there[color=green][color=darkred]
            > > > are
            > > > > > only 6 rows in the Personal table!
            > > > > >
            > > > > >
            > > > > >
            > > > > > "TomB" <shuckle@hotmai lXXX.com> wrote in message
            > > > > > news:um1DrRg1DH A.1704@tk2msftn gp13.phx.gbl...
            > > > > > > I have a feeling all of those inner joins aren't nesting the way[/color][/color]
            > you[color=green][color=darkred]
            > > > > want
            > > > > > > them to.
            > > > > > >
            > > > > > > I tried this query in Access and it returned a record if there[/color][/color][/color]
            was[color=blue]
            > a[color=green][color=darkred]
            > > > > > > matching "join" in all of the "union" tables. That is, I[/color][/color][/color]
            created[color=blue]
            > a[color=green][color=darkred]
            > > > > > Personal
            > > > > > > item and an item for each of the four other tables, then a join[/color][/color][/color]
            in[color=blue][color=green][color=darkred]
            > > > each
            > > > > of
            > > > > > > the other 4 tables. If any one of the join tables did not[/color][/color][/color]
            contain[color=blue][color=green]
            > > my[color=darkred]
            > > > > > > Personal then it didn't show up. I assume that's what you want.
            > > > > > >
            > > > > > > SELECT Personal.FName, Personal.LName, Personal.Prefer redName,
            > > > > > > Personal.Person alID
            > > > > > > FROM (((Personal INNER JOIN PersonalGift ON Personal.Person alID[/color][/color][/color]
            =[color=blue][color=green][color=darkred]
            > > > > > > PersonalGift.Pe rsonalID) INNER JOIN PersonalAbility ON
            > > > > Personal.Person alID
            > > > > > =
            > > > > > > PersonalAbility .PersonalID) INNER JOIN PersonalPeople ON
            > > > > > Personal.Person alID
            > > > > > > = PersonalPeople. PersonalID) INNER JOIN PersonalArea ON
            > > > > > Personal.Person alID
            > > > > > > = PersonalArea.Pe rsonalID
            > > > > > >
            > > > > > > You'll notice I took out the aliases (PersonalAbilit y PAB) I'm[/color][/color][/color]
            not[color=blue][color=green][color=darkred]
            > > > sure
            > > > > if
            > > > > > > they were causing the problem (they shouldn't have been) but I[/color]
            > > figured[color=darkred]
            > > > > I'd
            > > > > > > get them out of the way to be sure.
            > > > > > >
            > > > > > > So I think the problem is with the parentheses. Adding the[/color][/color][/color]
            where[color=blue][color=green][color=darkred]
            > > > clause
            > > > > > > didn't cause a problem.
            > > > > > >
            > > > > > >
            > > > > > > "middletree " <middletree@hto mail.com> wrote in message
            > > > > > > news:utggLva1DH A.2388@TK2MSFTN GP09.phx.gbl...
            > > > > > > > I've seen posts here and elsewhere which read something along[/color][/color]
            > the[color=green][color=darkred]
            > > > > lines
            > > > > > of
            > > > > > > > "PULLNG MY HAIR OUT!!!!!" or "HELLLLPPP! ". Well, I know[/color][/color]
            > that[color=green][color=darkred]
            > > > > kind
            > > > > > of
            > > > > > > > subject line isn't descriptive, but I sure can relate right[/color][/color][/color]
            now.[color=blue][color=green][color=darkred]
            > > > I've
            > > > > > been
            > > > > > > > struggling for days--days!!-- on this one simple query. I[/color][/color]
            > really[color=green][color=darkred]
            > > > need
            > > > > > to
            > > > > > > > get past this thing and move on. Please help.
            > > > > > > >
            > > > > > > > I have a classic ASP page, and it gives you 4 dropdowns. You[/color][/color][/color]
            can[color=blue][color=green][color=darkred]
            > > > > select
            > > > > > > any
            > > > > > > > or none of them. Each of them is built by an ACCESS table.[/color][/color][/color]
            These[color=blue]
            > 4[color=green][color=darkred]
            > > > > > tables
            > > > > > > > are union tables; they have just 2 fields: the PK from the[/color][/color]
            > master[color=green][color=darkred]
            > > > > table,
            > > > > > > > called Personal, and one of the 4 static tables that I call[/color]
            > > People,[color=darkred]
            > > > > > Area,
            > > > > > > > Ability, Gift.
            > > > > > > >
            > > > > > > > Anyway, when someone selects a value from one or more of the
            > > > > dropdowns,
            > > > > > > the
            > > > > > > > next page grabs the values and puts them into variables[/color]
            > > (strGiftID,[color=darkred]
            > > > > > > > strAbilityID, strAreaID, and strPeopleID). This is where I am
            > > > running
            > > > > > into
            > > > > > > > problems. If you see my previous threads on this, you'll see[/color][/color]
            > lots[color=green]
            > > of[color=darkred]
            > > > > > > > suggestions, and I have tried every one of them.
            > > > > > > >
            > > > > > > > Here's my current code:
            > > > > > > >
            > > > > > > > strSQL = "SELECT P.Fname, P.LName, P.PreferredName ,[/color][/color][/color]
            P.PersonalID[color=blue][color=green][color=darkred]
            > > > FROM
            > > > > > > > Personal P "
            > > > > > > > strSQL = strSQL & "INNER JOIN PersonalGift PG ON P.PersonalID[/color][/color][/color]
            =[color=blue][color=green][color=darkred]
            > > > > > > > PG.PersonalID "
            > > > > > > > strSQL = strSQL & "INNER JOIN PersonalArea PA ON P.PersonalID[/color][/color][/color]
            =[color=blue][color=green][color=darkred]
            > > > > > > > PA.PersonalID "
            > > > > > > > strSQL = strSQL & "INNER JOIN PersonalAbility PAB ON[/color][/color]
            > P.PersonalID[color=green]
            > > =[color=darkred]
            > > > > > > > PAB.PersonalID "
            > > > > > > > strSQL = strSQL & "INNER JOIN PersonalPeople PP ON[/color][/color][/color]
            P.PersonalID[color=blue]
            > =[color=green][color=darkred]
            > > > > > > > PP.PersonalID "
            > > > > > > >
            > > > > > > > If strGiftID <> "" Then
            > > > > > > > strWhere = "GiftID = "&strGiftID &" AND "
            > > > > > > > End if
            > > > > > > > If strAreaID <> "" Then
            > > > > > > > strWhere = strWhere & "AreaID = "&strAreaID &" AND "
            > > > > > > > End if
            > > > > > > > If strAbilityID <> "" Then
            > > > > > > > strWhere = strWhere & "AbilityID = "&strAbilityID& " AND "
            > > > > > > > End if
            > > > > > > > If strPeopleID <> "" Then
            > > > > > > > strWhere = strWhere & "PeopleID = "&strPeople ID&" AND "
            > > > > > > > End if
            > > > > > > >
            > > > > > > > If Len(strWhere) > 0 Then
            > > > > > > > ' Remove the last AND
            > > > > > > > strWhere = Left(strWhere, Len(strWhere) - 5)
            > > > > > > > strSQL = strSQL & "WHERE " & strWhere
            > > > > > > > End If
            > > > > > > > ----------------------------------------------
            > > > > > > >
            > > > > > > > Here's the error:
            > > > > > > >
            > > > > > > > 'P.PersonalID = PG.PersonalID INNER JOIN PersonalArea PA ON
            > > > > P.PersonalID
            > > > > > =
            > > > > > > > PA.PersonalID INNER JOIN PersonalAbility PAB ON P.PersonalID =
            > > > > > > > PAB.PersonalID INNER JOIN PersonalPeople PP ON P.PersonalID =
            > > > > > > > PP.PersonalID'.
            > > > > > > > /grace/list.asp, line 64
            > > > > > > >
            > > > > > > > (where line 64 is the line which executes the SQL statement)
            > > > > > > >
            > > > > > > >
            > > > > > > > Please, please let me know what you see that I am doing wrong.
            > > > > > > >
            > > > > > > > TIA
            > > > > > > >
            > > > > > > >
            > > > > > > >
            > > > > > > >
            > > > > > > >
            > > > > > > >
            > > > > > > >
            > > > > > > >
            > > > > > >
            > > > > > >
            > > > > >
            > > > > >
            > > > >
            > > > >
            > > >
            > > >[/color]
            > >
            > >[/color]
            >
            >[/color]


            Comment

            • middletree

              #21
              Re: SQL syntax--getting demoralized

              Where? Around the INNER JOINs? I don't see how that is possible, as the
              parentheses will be uneven, depending on what was selected.

              (watch the wrap)

              strSQL = "SELECT DISTINCT Personal.FName, Personal.LName,
              Personal.Prefer redName, Personal.Person alID "
              strSQL = strSQL & "FROM (((Personal "
              If strGiftID <> "" then
              strSQL = strSQL &"INNER JOIN PersonalGift ON Personal.Person alID
              =PersonalGift.P ersonalID) "
              End if
              If strAbilityID <> "" then
              strSQL = strSQL & "INNER JOIN PersonalAbility ON Personal.Person alID
              =PersonalAbilit y.PersonalID) "

              etc. See what I mean?


              "TomB" <shuckle@hotmai lXXX.com> wrote in message
              news:e2VN#6h1DH A.3220@tk2msftn gp13.phx.gbl...[color=blue]
              > Now you need to put your IFs back in there to limit the results.
              >[/color]


              Comment

              • TomB

                #22
                Re: SQL syntax--getting demoralized

                No, sorry. The way you originally had it.....


                if len(strGiftID)> 0 then
                sWhere="Persona lGift.GiftID=" & strGiftID & " AND "
                end if
                etc.

                strSQL=strSQL & sWhere



                "middletree " <middletree@hto mail.com> wrote in message
                news:OcLhjCi1DH A.2948@TK2MSFTN GP09.phx.gbl...[color=blue]
                > Where? Around the INNER JOINs? I don't see how that is possible, as the
                > parentheses will be uneven, depending on what was selected.
                >
                > (watch the wrap)
                >
                > strSQL = "SELECT DISTINCT Personal.FName, Personal.LName,
                > Personal.Prefer redName, Personal.Person alID "
                > strSQL = strSQL & "FROM (((Personal "
                > If strGiftID <> "" then
                > strSQL = strSQL &"INNER JOIN PersonalGift ON Personal.Person alID
                > =PersonalGift.P ersonalID) "
                > End if
                > If strAbilityID <> "" then
                > strSQL = strSQL & "INNER JOIN PersonalAbility ON Personal.Person alID
                > =PersonalAbilit y.PersonalID) "
                >
                > etc. See what I mean?
                >
                >
                > "TomB" <shuckle@hotmai lXXX.com> wrote in message
                > news:e2VN#6h1DH A.3220@tk2msftn gp13.phx.gbl...[color=green]
                > > Now you need to put your IFs back in there to limit the results.
                > >[/color]
                >
                >[/color]


                Comment

                • middletree

                  #23
                  Re: SQL syntax--getting demoralized

                  Oh, gosh. Dont' even know if I have that code; it's been changed so many
                  times.


                  "TomB" <shuckle@hotmai lXXX.com> wrote in message
                  news:OgRH0Mi1DH A.1924@TK2MSFTN GP10.phx.gbl...[color=blue]
                  > No, sorry. The way you originally had it.....
                  >
                  >
                  > if len(strGiftID)> 0 then
                  > sWhere="Persona lGift.GiftID=" & strGiftID & " AND "
                  > end if
                  > etc.
                  >
                  > strSQL=strSQL & sWhere
                  >
                  >
                  >
                  > "middletree " <middletree@hto mail.com> wrote in message
                  > news:OcLhjCi1DH A.2948@TK2MSFTN GP09.phx.gbl...[color=green]
                  > > Where? Around the INNER JOINs? I don't see how that is possible, as the
                  > > parentheses will be uneven, depending on what was selected.
                  > >
                  > > (watch the wrap)
                  > >
                  > > strSQL = "SELECT DISTINCT Personal.FName, Personal.LName,
                  > > Personal.Prefer redName, Personal.Person alID "
                  > > strSQL = strSQL & "FROM (((Personal "
                  > > If strGiftID <> "" then
                  > > strSQL = strSQL &"INNER JOIN PersonalGift ON Personal.Person alID
                  > > =PersonalGift.P ersonalID) "
                  > > End if
                  > > If strAbilityID <> "" then
                  > > strSQL = strSQL & "INNER JOIN PersonalAbility ON Personal.Person alID
                  > > =PersonalAbilit y.PersonalID) "
                  > >
                  > > etc. See what I mean?
                  > >
                  > >
                  > > "TomB" <shuckle@hotmai lXXX.com> wrote in message
                  > > news:e2VN#6h1DH A.3220@tk2msftn gp13.phx.gbl...[color=darkred]
                  > > > Now you need to put your IFs back in there to limit the results.
                  > > >[/color]
                  > >
                  > >[/color]
                  >
                  >[/color]


                  Comment

                  • middletree

                    #24
                    Re: SQL syntax--getting demoralized

                    Well, the problem got fixed. I have a firend, a former co-worker, and he
                    added some code fairly quickly. In anyone cares, here it is:

                    strSQL = "SELECT DISTINCT Personal.FName, Personal.LName,
                    Personal.Prefer redName, Personal.Person alID "
                    strSQL = strSQL & "FROM (((Personal LEFT OUTER JOIN PersonalGift ON " strSQL
                    = strSQL & "Personal.Perso nalID =PersonalGift.P ersonalID) "
                    strSQL = strSQL & "LEFT OUTER JOIN PersonalAbility ON Personal.Person alID
                    =PersonalAbilit y.PersonalID) "
                    strSQL = strSQL & "LEFT OUTER JOIN PersonalPeople ON Personal.Person alID=
                    PersonalPeople. PersonalID) "
                    strSQL = strSQL & "LEFT OUTER JOIN PersonalArea ON Personal.Person alID=
                    PersonalArea.Pe rsonalID"

                    If Len(strGiftID) Or Len(strAreaID) > 0 Or Len(strPeopleID ) > 0 Or
                    Len(strAbility) > 0 Then
                    strSQL = strSQL & " Where Personal.FName = Personal.FName "
                    If Len(strGiftID) > 0 Then
                    strSQL = strSQL & " And Personal.Person alID In (select PersonalID from
                    PersonalGift where GiftID = " & strGiftID & ")"
                    If Len(strAreaID) > 0 Then
                    strSQL = strSQL & " And Personal.Person alID In (select PersonalID from
                    PersonalArea where AreaID = " & strAreaID & ")"
                    If Len(strPeopleID ) > 0 Then
                    strSQL = strSQL & " And Personal.Person alID In (select PersonalID from
                    PersonalPeople where PeopleID = " & strPeopleID & ")" If Len(strAbilityI D) >
                    0 Then
                    strSQL = strSQL & " And Personal.Person alID In (select PersonalID from
                    PersonalAbility where AbilityID = " & strAbilityID & ")"

                    Thanks, everybody, for your time!



                    Comment

                    Working...