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
 General SQL Server Forums
 New to SQL Server Programming
 Counting Data on a Certain Date

Author  Topic 

sampcuk
Starting Member

32 Posts

Posted - 2009-03-04 : 09:49:04
Hi,

I need to count how many employees we had employed on a certain date using SQL. My aim is to work out labour turnover by using leavers for a certain period divided by the current staff x 100.

How do I get the employees on a certain date though? I have been at it for ages on this!

Thanks
S

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-03-04 : 09:52:43

select count(*) from employees
where date_col>=dateadd(day,datediff(day,0,@date),0)
and date_col<dateadd(day,datediff(day,0,@date),1)


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

sampcuk
Starting Member

32 Posts

Posted - 2009-03-04 : 10:20:14
Sorry but this is a sill question, where do I put the desired date in? I am getting an error message about a scalar variable?!
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-03-04 : 10:22:18
quote:
Originally posted by sampcuk

Sorry but this is a sill question, where do I put the desired date in? I am getting an error message about a scalar variable?!


@date ia place where you put your date value in

DECLARE @Date datetime
SET @date= your date value here

select count(*) from employees
where date_col>=dateadd(day,datediff(day,0,@date),0)
and date_col<dateadd(day,datediff(day,0,@date),1)


Go to Top of Page
   

- Advertisement -