all groups > sql server reporting services > september 2007 >
You're in the

sql server reporting services

group:

DateAdd


DateAdd awakin
9/28/2007 7:17:42 PM
sql server reporting services:
Hello Everyone,

I trying to build an SQL statement that includes the last twelve
months in the report. When I use the DATEADD function ie >=
DATEADD(MM, - 12, GETDATE())) the report brings back data 12 months
from the current date. I would like to include the whole month not
just the current date. I hope this make sense!

R/ A. Akin
Re: DateAdd Simon Sabin
9/30/2007 12:00:00 AM
Hello awakin,

You need to take of the day of the month as well day(getdate()) returns the
day of the month but the simplest is to build the date from scratch i.e

convert(datetime, cast((year(getdate())-1) *100 + month(getdate())as char(6))
+ '01' ,112)

This builds a date string in the ISO format yyyymmdd and then converts it
to a date using the relevant coversion style for the ISO format

Simon Sabin
SQL Server MVP
http://sqlblogcasts.com/blogs/simons


[quoted text, click to view]

Re: DateAdd awakin
10/1/2007 5:49:43 PM
[quoted text, click to view]

Simon,


Thanks for the response; here is what worked for me.
[quoted text, click to view]
CAST(MONTH(GETDATE()) AS VARCHAR) + '-01' AS DATETIME)))

This allowed me to return the appropriate data.

r/ A.Akin


AddThis Social Bookmark Button