SQL Get data FROM a Month


SELECT * FROM dates WHERE

tdate

>CONVERT(Datetime,(Convert(varchar(2),@monthInt)+‘/1/’+‘2008’))AND tdate<

dateadd

(month,datediff(month,-1,CONVERT(Datetime,(Convert(varchar(2),@monthInt)+‘/1/’+‘2008’))),0)

Or

SELECT

* FROM dates WHERE

tdate

>CONVERT(Datetime,(Convert(varchar(2),@monthInt)+‘/1/’+Convert(varchar(4),@yearInt)))AND tdate<dateadd(month,datediff(month,-1,CONVERT(Datetime,(Convert(varchar(2),@monthInt)+‘/1/’+Convert(varchar(4),@yearInt)))),0)

Advertisements


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s