Q:

Stored procedure insert value using if else condition

I have written a stored procedure which is working fine. I want to calculate average of fd.benefitscontributions which i can do as AVG(fd.benefitscontributions) . 
If the result is greater than 50 then insert 'good' else 'bad' in the  status column in the if_funddetails table. if_funddetails has 4 columns currently i am inserting values in three column but the forth column ,i.e, status value is based on the average of fd.benefitscontributions
 INSERT INTO if_funddetails  ( d.fundcode,   d.fundname, fd.benefitscontributions )
  SELECT DISTINCT  d.fundcode, d.fundname, fd.benefitscontributions
  FROM   dbo.ws_funddetail AS d 
         LEFT OUTER JOIN dbo.v_fundnooutofpocket AS nop 
                      ON d.funddetailid = nop.funddetailid 
         INNER JOIN dbo.ws_funddata AS fd 
                 ON nop.fundreportid = fd.fundreportid 

I can get the average but how to add value 'good' or 'bad' in the status column is not sure. Any help would be appreciated.

A:

Try Case statement with your AVG function, as you got AVG already
CASE WHEN AVG(FieldName)>50 THEN 'Good' ELSE 'Bad' END AS 'Status'

Note: To use aggregate function, you have to Group other columns

