Expert,
I am getting following error, any idea?
Msg 144, Level 15, State 1, Line 17
Cannot use an aggregate or a subquery in an expression used for the group by list of a GROUP BY clause.
SELECT
[SDDoc],
[Soldtopt],
[tradingname],
[DlvDate],
SUM(try_cast(Netvalue as float)) as Netvalue,
count(distinct SDDoc) as Salesdoc ,
count(distinct case when Netvalue = '0' then 1 else null end) as ZeroValue ,
count(distinct SDDoc) - count(distinct case when Netvalue = '0' then 1 else null end) As Result
FROM [FOC].[dbo].[foc]
WHERE dlvdate='25.01.2017'
GROUP by case when( count(distinct SDDoc) - count(distinct case when Netvalue = '0' then 1 else null end) ) = 0 then [SDDoc] END,Soldtopt,tradingname,DlvDate having count(distinct SDDoc) = 1 and count(distinct case when Netvalue = '0' then 1 else null end) = 1