0

I want to use Default value column in GROUP BY. The default column is created in Select statement.

I have tried to use the default column value 'A' in group by(I know i cannot use the alias value).

This is what I have tried.

Select Name, 'A' as 'ID',SUM(Amount) FROM Customer
GROUP BY Name, 'A'

I am getting the following error message:

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

1
  • 1
    As 'A' is a constant, you don't need to add it to the group by list. And having single quotes around 'ID' might be causing issues too. Get rid of them or use [ID]. Commented Jun 6, 2019 at 6:24

1 Answer 1

3

Grouping by that additional column will not do any difference and will be the same as:

Select Name, 'A' as 'ID',SUM(Amount) FROM Customer
GROUP BY Name
Sign up to request clarification or add additional context in comments.

1 Comment

Well, technically adding 'A' to the GROUP BY does make a difference because it results in an error. However, if it worked, it wouldn't logically affect the results.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.