question

ashutosh8051singh avatar image
ashutosh8051singh asked

Monthly value calculation basef on daily value ?

For a given column "amount" daily value is given as 10. How to display monthly value based on it for all 12 months in a year ? Jan - 31 days Feb - 28 days Apr - 30 days in a single sql query ?
developer
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Jon Crawford avatar image
Jon Crawford answered
DECLARE @startDate date; SET @startDate = '1/1/2018'; WITH Tally AS ( SELECT N = 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9 UNION SELECT 10 UNION SELECT 11 UNION SELECT 12 ) SELECT convert(varchar,EOMONTH(@startDate,N-1),107) FROM Tally;
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.