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
 SQL Server Development (2000)
 Querying Dates

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-08-21 : 10:29:02
martin writes "This is probably a very easy question, but as i am a sql dunce could you answer this.

I want to run a query aganst a date (format dd/mm/yy)
so that it generates a monthly report. how do i query the date format so that it only returns entries within a specific month ?


thanks
mc"

nr
SQLTeam MVY

12543 Posts

Posted - 2002-08-21 : 12:01:13
Is the date character in that format or a datetime?

if a datetime

from tbl
where datepart(mm,dte) = @monthno

if char
from tbl
where datepart(mm,convert(datetime,dte,103)) = @monthno

do a similar thing for the year if necessary
could also
declare @startdate datetime

select @startdate = '1 sep 2002' ,

from tbl
where dte >= @startdate
and dte < dateadd(mm, 1, @startdate)



==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -