Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7630949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T06:13:41+00:00 2026-05-31T06:13:41+00:00

The following query works in MS Access, but it does not work in MS

  • 0

The following query works in MS Access, but it does not work in MS SQL Server:

SELECT
  tblSession.PatientID as PID,
  max(tblSession.SessionAttend) - 
    min(tblSession.SessionAttend) + 1 as NumSA,
  max(tblSession.SessionSched) - 
    min(tblSession.SessionSched) + 1 as NumSS FROM
  (
    SELECT top 100 percent
      tblSession.PatientID,
      tblSession.SessionNumber,
      tblSession.SessionDate,
      tblSession.SessionAttend,
      tblSession.SessionSched FROM
      tblPatient INNER JOIN tblSession ON
        tblPatient.PatientID = tblSession.PatientID) WHERE
        (tblSession.SessionDate >= '12/8/2010') AND
        (tblSession.SessionDate <= '5/18/2011') AND
        (tblSession.Status = '2') ORDER BY 
          tblSession.PatientID, tblSession.SessionNumber
  ) GROUP BY tblSession.PatientID

In SQL Server, it gives the error “Incorrect syntax near the keyword ‘GROUP’.” When I hover over the GROUP keyword, the tooltip displays “Incorrect syntax near ‘GROUP’. Expecting AS, ID, or QUOTED_ID.” I don’t understand. Can anyone tell me how to make this query work?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T06:13:42+00:00Added an answer on May 31, 2026 at 6:13 am

    The derived table in () needs an alias, and its column references in the SELECT list updated accordingly:

    SELECT top 100 percent
      ALIASNAME.PatientID as PID,
      max(ALIASNAME.SessionAttend) - 
        min(ALIASNAME.SessionAttend) + 1 as NumSA,
      max(ALIASNAME.SessionSched) - 
        min(ALIASNAME.SessionSched) + 1 as NumSS FROM
      (
        SELECT top 100 percent
          tblSession.PatientID,
          ...
          ...
          ...
          ...
              tblSession.PatientID, tblSession.SessionNumber
      -- This derived table needs an alias
      ) ALIASNAME 
      GROUP BY ALIASNAME.PatientID
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following query works on Oracle 10.2.0.1.0 on windows,but doesn't work on Oracle 10.2.0.2.0
I have the following query which works fine with MySQL but refuses to work
I have the following which works in SQL Query Analyzer . select oh.* from
This has to be obtained from a remote machine. The following query works not
I am using following query which works fine for me except one problem SELECT
i've been using the following query: select LEN(columnname) as columnmame from dbo.amu_datastaging This works,
I am trying the following query in MS-Access 2007, but it fails on the
I'm working with C# .Net and ms-access database. I have the following SQL query:
The following query works as long as I can add DataRelations. However, the relation
Is there a reason why this query doesn't work? The following query will work

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.