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)
 How to get a query to return more rows than existing in the source table.

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2004-12-06 : 08:29:07
Kevin writes "I've got an (simplified for example purposes) employee table that contains two fields: EmployeeName and HireDate.

Below is a sample dataset:

EmployeeName Hiredate
John 1/1/04
Tom 2/1/04
Pete 3/1/04

I'd like to create a query that would return list of employees by month if they worked in that month over a user supplied date range. For example, if the user wanted to query 1/1/04 - 4/30/04, they would get the following result set:

Month Year Employee
1 2004 John
2 2004 John
2 2004 Tom
3 2004 John
3 2004 Tom
3 2004 Peter
4 2004 John
4 2004 Tom
4 2004 Peter

I won't know in advance the date range. I could be one month, twelve months, etc. Can this be done through some kind of cross joins combined with a few extra tricks?"

robvolk
Most Valuable Yak

15732 Posts

Posted - 2004-12-06 : 08:29:53
Take a look here:

http://www.sqlteam.com/item.asp?ItemID=3332

Also check the comments section at the bottom (it's a link), there may be other solutions posted there.
Go to Top of Page
   

- Advertisement -