Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Need to create a view of 1 months worth of data

Author  Topic 

fiesta_donald
Starting Member

4 Posts

Posted - 2002-03-14 : 12:32:45
I need to create a view that queries a table and returns data from the first of the month and ends on the last day of the month.

(i.e.: select * from foo_table where timestamp >= first_day_of_month and timestamp <= last_day_of_month)

Does anyone know how to do this? I am having a hard time using getdate and the date functions.

thank you,
Mark

nr
SQLTeam MVY

12543 Posts

Posted - 2002-03-14 : 12:45:22
I assume the timestamp is a datetime and not a timestamp datatype.

something like

where timestamp >= convert(varchar(8),dateadd(dd,(datepart(dd,getdate())-1) * -1, getdate()),112)
and timestamp < convert(varchar(8),dateadd(mm,1,dateadd(dd,(datepart(dd,getdate())-1) * -1, getdate())),112)


==========================================
Cursors are useful if you don't know sql.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -