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

  • SEARCH
  • Home
  • 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 8118917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T04:38:40+00:00 2026-06-06T04:38:40+00:00

I have a SQL Server query which runs just fine — until I add

  • 0

I have a SQL Server query which runs just fine — until I add a computed column to the SELECT statement. Then I get an odd SQL Server error.

Here’s the SQL:

SELECT
    outmail_.MessageID_, 
    CONVERT(VARCHAR(10),outmail_.Created_,120) AS 'Issue', 
    lyrReportSummaryData.mailed, 
    lyrReportSummaryData.successes, 
    COUNT(*) AS 'opens',
    COUNT(DISTINCT clicktracking_.MemberID_) AS 'unique_opens', 
    convert(decimal(3,1),((convert(float,[unique_opens]))/[successes]) * 100) AS 'Rate'
FROM 
    outmail_ 
RIGHT JOIN 
    clicktracking_ ON clicktracking_.MessageID_ = outmail_.MessageID_
RIGHT JOIN 
    lyrReportSummaryData ON lyrReportSummaryData.id = clicktracking_.MessageID_ 
GROUP BY  
    outmail_.MessageID_, CONVERT(VARCHAR(10), outmail_.Created_,120), 
    lyrReportSummaryData.mailed, lyrReportSummaryData.successes

The problem is the line beginning with the convert(decimal ... When it is included, I get the following error:

Error 8120: Column ‘lyrReportSummaryData.unique_opens’ is invalid in
the select list because it is not contained in either an aggregate
function or the GROUP BY clause.

I’m not sure how to resolve the error since I don’t know how to use it in a GROUP BY clause (and it doesn’t seem that I should need to do so).

Any suggestions for how to proceed? Thanks.

  • 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-06T04:38:41+00:00Added an answer on June 6, 2026 at 4:38 am

    I’m sure someone with better DBA skills than me can point out a more efficient way of doing this, but…

    If you perform the bulk of your query as an sub-query, you can then do the calculations on the result of your sub-query:

     SELECT 
        MessageID_, 
        Issue, 
        mailed, 
        successes, 
        opens, 
        unique_opens, 
        convert(decimal(3,1),((convert(float,[unique_opens]))/[successes]) * 100) AS 'Rate'
    
     FROM 
     (SELECT
          outmail_.MessageID_, 
          CONVERT(VARCHAR(10),outmail_.Created_,120) AS 'Issue', 
          lyrReportSummaryData.mailed, 
          lyrReportSummaryData.successes, 
          COUNT(*) AS 'opens',
          COUNT(DISTINCT clicktracking_.MemberID_) AS 'unique_opens'
    
    
        FROM outmail_ 
        RIGHT JOIN clicktracking_ ON clicktracking_.MessageID_ = outmail_.MessageID_
        RIGHT JOIN lyrReportSummaryData ON lyrReportSummaryData.id = clicktracking_.MessageID_ 
    
        GROUP BY  outmail_.MessageID_, CONVERT(VARCHAR(10), outmail_.Created_,120), lyrReportSummaryData.mailed, lyrReportSummaryData.successes
       ) subquery /* was 'g' */
    

    Effectively what this does is runs the grouping, and then based on that, does the calculation afterwards.

    Subqueries must be given an alias (in this instance ‘subquery’) – even if you don’t use that alias name.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have the following SQL Query which runs on SQL Server CE 4 SELECT
I have the following query which runs fine on all of my sql server
I have VBA code to run a query in SQL-Server 2008. It runs fine
I have an SQL LIKE query running on mySQL which runs fine on my
I have a nested query which when I execute in SQL server 2008 management
I'm using Sql-Server, and I have the below query which returns all columns that
I have written a query in Sql server 2008. select select * from program
In sql server 2008, I have the following query: select c.title as categorytitle, s.title
I have the following in a SQL Server query which I have to convert
Currently I have a SQL server column of type nvarchar(max) which has text that

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.