0

I'm tried to execute the below query in MSSQL 2008 R2,but its throwing error. THE QUERY IS:

    SELECT (n_artifactType+(' '+ n_actionPerformed)) AS actionperformed, 
    COUNT(n_actionPerformed) total FROM notifications WHERE   n_project='JupiterQA'
    GROUP BY actionperformed order by n_actionPerformed;

ERROR IS:

Msg 207, Level 16, State 1, Line 1
Invalid column name 'actionperformed'.

Using 'actionperformed' as alias name even though its throwing error. How can I execute above query without error.

Arunprasanth K V
  • 20,733
  • 8
  • 41
  • 71
user3114967
  • 639
  • 5
  • 15
  • 38

2 Answers2

2

By the looks of it actionperformed is an alias name and not an actual table field (or expression of), which is required by a group by clause.

Suggest group by (n_artifactType+(' '+ n_actionPerformed)) instead.

Interestingly order by would however be happy with an alias.

Chris du Preez
  • 539
  • 3
  • 8
0

The error is in group by section of the query, group by will not work with alias change it to actual expression i.e.(n_artifactType+(' '+ n_actionPerformed))

Arunprasanth K V
  • 20,733
  • 8
  • 41
  • 71
Rao Y
  • 99
  • 5