Hello Everyone,
I have this code that I count a field in my SQL and I have a specific column which I need to count distinct the values but I don't know how to use it in this format
This is the code :
SELECT
Sum(Price) As Total,
CONVERT(char(7), date, 120) As [year],
Department ,
Sum Dinstict (CONVERT(INT, CONVERT(VARCHAR(MAX),quantity))) as Lesh
FROM
dbo.Expenses
WHERE
CONVERT(char(7), date, 120) Between '2020-01' And '" 2020-07"' AND
Department = 'FixCost'
GROUP BY
CONVERT(char(7), date, 120),
Department
)
SELECT
Total,
[year],
Department as 'Department',
Concat(SUM(Convert(int,Convert(Varchar(MAX),(Lesh)))) OVER (),'') As GrandTotal
FROM
cte
WHERE
[year] Is Not Null
What I have tried: I need to use it here :
tal,
[year],
Department as 'Department',
Concat(SUM(Convert(int,Convert(Varchar(MAX),(Lesh)))) OVER (),'') As GrandTotal
I tried this, but it doesn't work :
Concat(COUNT(Convert(int,Convert(Varchar(MAX),(Distinct,Lesh)))) OVER (),'')
Thank you, Blessings