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
 xml

Author  Topic 

aidmondo
Starting Member

23 Posts

Posted - 2012-05-25 : 06:17:08
I have an employee table with the following columns;
(EmployeeID, FirstName, LastName, Address, Phone, Title)
The table have been created and records have been entered.

I also have a created Events table with (EventID, EventName, EventTypeID, LocOfEvent, StartDate, EndDate, EmployeeID (as a foreign key)). Records have also been entered into this table.

How can i store the information of all employees who have managed an event in the current month in a text file.
Note: When the month changes the details of the employees also changes to the current month.


aidmondo

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-05-25 : 09:46:21
I'm hoping you need only employee details if not you've to change below to join to return event details too


SELECT *
FROM Employee e
WHERE EXISTS(SELECT 1
FROM Events
WHERE EmployeeID = e.EmployeeID
AND StartDate < DATEADD(mm,DATEDIFF(mm,0,GETDATE())+1,-1)
AND EndDate > DATEADD(mm,DATEDIFF(mm,0,GETDATE()),0)
)


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -