HestonJames
Programmer
Hello Guys,
I have a scheduled script that runs every day and I want to pull a list of customers who should be billed on this day of the month.
Now, I've mocked up a little data to show you how I want this to work.
Now, what I want to do is pass in a date and have it return a list of customers for which the day of the month passed in matches their first billing date.
So for instance I pass in '20091120' and it'll return the first customer as their first billing date was the 20th, you see?
Now, the difficulty comes with people like the second customer in my example, whereby their first billing date is on a day which doesn't exist in every month, such as the 29th 30th and the 30st. In these instances I want these customers to be returned on the last day of the month, so if I passed in a date like '20100228' then it'll return all those records who's first billing date was for the 29th 30th and 31st to ensure they get billed very month.
Does that make sense? how would you go about coding that logic?
Thanks in advance chaps,
Heston
I have a scheduled script that runs every day and I want to pull a list of customers who should be billed on this day of the month.
Now, I've mocked up a little data to show you how I want this to work.
Code:
DECLARE @Customers TABLE (
Customer_ID int IDENTITY(1,1) NOT NULL,
FirstBillingDate datetime
);
Insert Into @Customers (
FirstBillingDate
)
Values (
'20090720'
);
Insert Into @Customers (
FirstBillingDate
)
Values (
'20090531'
);
Select * From @Customers
Now, what I want to do is pass in a date and have it return a list of customers for which the day of the month passed in matches their first billing date.
So for instance I pass in '20091120' and it'll return the first customer as their first billing date was the 20th, you see?
Now, the difficulty comes with people like the second customer in my example, whereby their first billing date is on a day which doesn't exist in every month, such as the 29th 30th and the 30st. In these instances I want these customers to be returned on the last day of the month, so if I passed in a date like '20100228' then it'll return all those records who's first billing date was for the 29th 30th and 31st to ensure they get billed very month.
Does that make sense? how would you go about coding that logic?
Thanks in advance chaps,
Heston