Thanks for your quick response.... Here is the code to create the table and sample data
CREATE TABLE [dbo].[account_DeactivationReactivationHistory](
[ID] [bigint] IDENTITY(1,1) NOT NULL,
[account_id] [int] NOT NULL,
[Active] [bit] NOT NULL,
[status_date] [datetime] NOT NULL,
CONSTRAINT [PK_account_DeactivationReactivationHistory] PRIMARY KEY CLUSTERED ([ID] ASC)
) ON [PRIMARY]
INSERT INTO account_DeactivationReactivationHistory
(account_id, active, status_date)
VALUES (1234, 1, '2/3/2007 14:00')
INSERT INTO account_DeactivationReactivationHistory
(account_id, active, status_date)
VALUES (1234, 0, '6/15/2007 10:00')
INSERT INTO account_DeactivationReactivationHistory
(account_id, active, status_date)
VALUES (1234, 1, '11/12/2007 11:00')
INSERT INTO account_DeactivationReactivationHistory
(account_id, active, status_date)
VALUES (1234, 0, '2/5/2008 17:00')
I'd like to be able to create a function that returns true or false based on if a particular account_id is active during a particular date range. For example in regards to the sample data, I'd like to check to see if account_id 1234 was active during the date range of 7/1/2007 and 12/30/2007.
Also, take into consideration that some of our users will make a mistake and activate someone and immediately inactivate them again on the same day. I would not want to count that particular as active on that day.
Thanks