Microsoft SQL Server: Error with Group By
NickName:Ong K.S Ask DateTime:2022-12-09T09:54:03

Microsoft SQL Server: Error with Group By

I'm new to Microsoft SQL Server 2014. I run this SQL code:

SELECT TOP(10) 'DBSG' as seek_entity, * 
FROM DBSG..PM00200

and get this result:

enter image description here

Next, I want to find out total line items for that entity with code below.

WITH vw_pm00200_all AS
(
    SELECT TOP(10) 
        'DBSG' as seek_entity, *    
    FROM 
        DBSG..PM00200
)
SELECT
    seek_entity,
    COUNT(*) AS total
FROM
    vw_pm00200_all
GROUP BY
    1

Sadly, I get this error. I have no idea why it failed.

Msg 164, Level 15, State 1, Line 9
Each GROUP BY expression must contain at least one column that is not an outer reference.

Lastly, please advise is Microsoft SQL Server based on Transact-SQL?

Copyright Notice:Content Author:「Ong K.S」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/74738157/microsoft-sql-server-error-with-group-by

More about “Microsoft SQL Server: Error with Group By” related questions

Microsoft SQL Server: Error with Group By

I'm new to Microsoft SQL Server 2014. I run this SQL code: SELECT TOP(10) 'DBSG' as seek_entity, * FROM DBSG..PM00200 and get this result: Next, I want to find out total line items for that entity

Show Detail

SQL Server GROUP BY error

Here is the query I am trying to run: SELECT TOP 5 PageComment.ID FROM PageComment WHERE PageComment.ParentID IN (SELECT ID FROM ProjectPage) GROUP BY PageComment.ParentID What I want to...

Show Detail

Error occurs in Microsoft SQL Server

Could you please suggest where syntax mistake occurs? When I run this code in Oracle, I have no mistake, but in Microsoft SQL Server I catch an error connected with syntax "near where" Thanks in

Show Detail

Microsoft sql server 2008 Error: 53?

I just installed sql server 2008 . When I tried to connect it . It was showing this message : *TITLE: Connect to Server Cannot connect to SQLServer. ADDITIONAL INFORMATION: A network-related or

Show Detail

Microsoft SQL Server, Error 916

I'm using Microsoft SQL Server 2012 Management Studio Express. I have detached one of my databases (it was in my office server) and .mdf and .ldf files are saved to MSSQL folder (on my local server).

Show Detail

Microsoft SQL server to select Top N group

There are a lot of answers about how to select n rows from each group. But what I am looking for is to select every row from top N group, for example I have the data below: id group 1 a ...

Show Detail

How can I resolve this error in Microsoft SQL Server Management Studio

I have created a database online clinic management system having 10 tables. Now I want to create a database diagram for this database but I'm getting the following error. Please share your knowledg...

Show Detail

Microsoft SQL Server Management Studio connection error

I am getting an error while opening the Microsoft SQL Server 2014 Management Studio: named pipe error 40( Microsoft SQL server could not connect) Microsoft SQL server error: 67.

Show Detail

Unable to change Authentication Mode in SQL Server: Microsoft SQL Server, Error: 229

I have just installed SQL Server 2016 Service Pack 1 Express and SSMS 2017 using the Basic option from the installation wizard. After installation, I wanted to change the mode of authentication from

Show Detail

getting error while connecting microsoft sql server

I had installed Microsoft SQL Server Management Studio Express.But after installation when i connect the SQL server I am getting the following error. TITLE: Connect to Server Cannot connect to...

Show Detail