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)
 help with stored procedure

Author  Topic 

php95saj
Starting Member

43 Posts

Posted - 2002-08-09 : 07:50:06
I am trying to get a count of countries on Jobs table between to show how many jobs were submitted between two dates from each country.
here is somethign I was thinking to do but it doesn't work:

declare @dateFrom datetime, @dateTo datetime
SET @dateFrom = '8/1/01'
SET @dateTo = '8'8'02

SELECT COUNT(tblJobs.countryID)
FROM tblJobs
WHERE DATEDIFF(d, @dateFrom, tblJobs.jobCompletionDate) >=0
AND DATEDIFF(d, @dateTo, tblJobs.jobCompletionDate) <=0
GROUP BY tblJobs.countryID



nr
SQLTeam MVY

12543 Posts

Posted - 2002-08-09 : 08:10:31
always use dates in yyyymmdd format then you won't get format problems.

declare @dateFrom datetime, @dateTo datetime
SET @dateFrom = '20010801'
SET @dateTo = '20020808'

SELECT COUNT(*)
FROM tblJobs
where tblJobs.jobCompletionDate < @dateTo
and tblJobs.jobCompletionDate >= @dateFrom

or maybe
SELECT COUNT(*)
FROM tblJobs
where tblJobs.jobCompletionDate between @dateFrom and @dateTo


==========================================
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 -