Last post Dec 21, 2017 10:05 AM by JagjitSingh
Dec 18, 2017 06:06 AM|JagjitSingh|LINK
I have parameter Month & Year . I have written sql like this
Select Location , (Select Sum(Amount) from Temp where Month(Date) = @month and Year(date) = &year) as MTD
from Temp A
Now i want YTD value how we can get it.
Dec 18, 2017 06:11 AM|Omkar Mhaiskar|LINK
Refer below query
coalesce(sum(YourTable2.amount), 0) as ytdamount
left outer join YourTable as YourTable2
on YourTable.id= YourTable2.id
and YourTable.date > YourTable2.Date
group by YourTable.id,
Dec 18, 2017 06:18 AM|JagjitSingh|LINK
I have Month , Year as parameter not Date. I am trying like this but not working
SELECT A.[Location], Case When @Month <= 3 Then (Select Sum([Total Rounded Amt_]) * - 1
WHERE [Location] = A.[Location] AND [Date] >= @Year-1 + '/04/01' ) AS [YTD],
FROM Test AS A
WHERE [Location] in (@Location)
Dec 19, 2017 07:35 AM|Deepak Panchal|LINK
you had mentioned that,"I am trying like this but not working".
did you got any error?
if yes, try to post the error. it will help us to understand the issue in better way.
or did you get undesirable output?
try to provide a detail information.
it will help us to provide better suggestions.
Dec 21, 2017 10:05 AM|JagjitSingh|LINK
Resolved using Convert function