none
How do I fix this problem

    Question

  • create procedure ttt
    @degree nvarchar(50)
    as
    select price=SUM(price),fname from stdsalary
    select * from stdsalary
    where degree=@degree

     -----------------------------

    Msg 8120, Level 16, State 1, Procedure ttt, Line 4
    Column 'stdsalary.fname' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.

    Friday, June 28, 2013 5:28 PM

Answers

All replies

  • Remove fname, or replace with Max(fname) or Min(fname)

    select price=SUM(price),Max(fname) from stdsalary
    
    Or
    
    select price=SUM(price) from stdsalary

    Friday, June 28, 2013 5:34 PM
  • create procedure ttt
    @degree nvarchar(50)
    as
    select fname, SUM(price) as price from stdsalary
    where degree=@degree
    group by fname


    Best Luck, Shenoy

    Friday, June 28, 2013 5:35 PM
  • create procedure ttt
    @degree nvarchar(50)
    as
    select  SUM(price)Over(partition By fname) as price, fname from stdsalary 
    where degree=@degree

    Friday, June 28, 2013 7:29 PM
    Moderator
  • The syntax is incorrect. If there are two qualifying rows, then which of the two fnames would you want to select?

    If you know there is only ever going to be one unique fname for your selection, then you can simply add "GROUP BY fname" to your query.

    if you want something else, then you first have to tell what you want before you can get proper advice on a solution.


    Gert-Jan

    Sunday, June 30, 2013 11:39 AM