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 7997987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:06:27+00:00 2026-06-04T15:06:27+00:00

I have been trying to do a query using Microsoft SQL Server 2008 R2,

  • 0

I have been trying to do a query using Microsoft SQL Server 2008 R2, grouping the total sum of points by intervals. However, I can´t get this to work. This is my code:

SELECT interval_total, COUNT(*) FROM(
SELECT clients.clientId, total.TotalPoints,
CASE
    WHEN TotalPuntos >=5000 THEN 5000
    WHEN TotalPuntos >= 1000 THEN 1000
    WHEN TotalPuntos >= 500 THEN 500
    WHEN TotalPuntos >= 100 THEN 100
    ELSE 0
END as interval_total
FROM
    [TotalSumOfPoints] total,
    [Client] clients
WHERE total.clientId = clients.clientId
AND clients.cardId LIKE '2001%')
GROUP BY interval_total

With this error:

Msg 156, Level 15, State 1, Line 17
Incorrect syntax near the keyword 'GROUP'.

I have been reading different posts, and had come to the conclusion that is IS possible to do this kind of query, by placing the CASE statement within a subquery (I came to this conclusion reading this post). Clearly I am doing something wrong. Any help?

  • 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-06-04T15:06:28+00:00Added an answer on June 4, 2026 at 3:06 pm

    Your problem is just that you need to provide an alias for the subquery, like so:

    SELECT interval_total, COUNT(*) FROM(
    SELECT clients.clientId, total.TotalPoints,
    CASE
        WHEN TotalPuntos >=5000 THEN 5000
        WHEN TotalPuntos >= 1000 THEN 1000
        WHEN TotalPuntos >= 500 THEN 500
        WHEN TotalPuntos >= 100 THEN 100
        ELSE 0
    END as interval_total
    FROM
        [TotalPuntosPorCuenta] total,
        [SanRoque].[dbo].[Socio] clients
    WHERE total.clientId = clients.clientId
    AND clients.cardId LIKE '2001%') tbl /* <--- here */
    GROUP BY interval_total
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to find a way to do this query using a
I have been trying to build an SQL query to return matches between three
I'm using Microsoft SQL Svr Mgmt Studio 2008. I don't have access to create
Recently I have been working with a SQL Server database and I was trying
I am using Zend Framework and have been trying to do a joined query
I've been trying to query an email address using the following statement, however after
I have been trying to write a bare-bones ping scanner using Perl for internal
I've recently been toying with data migration into Microsoft Dynamics CRM using MS SQL
I have been trying to set the TTL on ICMP packets using the boost::asio::ip::unicast::hops
I have been trying to connect to my database using pdo on godaddy with

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.