Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Stumped on SQL

  • 05-01-2008 2:00pm
    #1
    Registered Users, Registered Users 2 Posts: 879 ✭✭✭


    I'm trying to use a subquery in the sql below but not having any luck. Anyone spot my error?

    Basically, the subquery will return something like:

    loc1 dirs1 2
    loc2 dirs2 1
    loc1 dirs1 3

    and then I want the main query to give:

    loc1 5
    loc2 1

    sSQL = "SELECT [mainlist].Location, Sum(CountofNCP) AS SumofNCP FROM (SELECT [mainlist].Location, dirs.directions, Count(mainlist.ncp_tt) AS CountOfNCP FROM mainlist INNER JOIN dirs ON [mainlist].Location = dirs.areadirs GROUP BY 'Location, [mainlist].Level, dirs.directions HAVING [mainlist].Level = " & mylevel_form & " OR [mainlist].Level = " & mylevel_form -1 & " OR [mainlist].Level = " & mylevel_form +1 & ") ;"


Comments

  • Moderators, Politics Moderators Posts: 41,217 Mod ✭✭✭✭Seth Brundle


    As you don't say what is going wrong, I'm just guessing the following:
    The single quote at 'Location is the source.
    sSQL = "
    SELECT [mainlist].Location, Sum(CountofNCP) AS SumofNCP 
    FROM (
         SELECT [mainlist].Location, dirs.directions, Count(mainlist.ncp_tt) AS CountOfNCP 
         FROM mainlist 
         INNER JOIN dirs ON [mainlist].Location = dirs.areadirs 
         GROUP BY [B]'Location[/B], [mainlist].Level, dirs.directions 
         HAVING [mainlist].Level = " & mylevel_form & " 
         OR [mainlist].Level = " & mylevel_form -1 & " 
         OR [mainlist].Level = " & mylevel_form +1 & ") ;"
    


  • Registered Users, Registered Users 2 Posts: 879 ✭✭✭sirpsycho


    The quote at 'Location was part of the problem but I forgot to add in the GROUP BY for the main query.


Advertisement