Why do you have to loop? What is the requirement that states you have to process a single day at a time?
FWIW, you could build a stored procedure that accepts as input the date you want to search, and query for everything on that one date. Example:
CREATE PROCEDURE dbo.MySingleDaySearch
@inputDate datetime
AS
DECLARE @startDate datetime;
DECLARE @endDate datetime;
SET @startDate = dateadd(day, datediff(day, 0, @inputDate), 0); -- remove time portion
SET @endDate = dateadd(day, 1, @startDate); -- set the end date to tomorrow
SELECT ...
FROM dbo.MyTable t
WHERE t.MyDateColumn >= @startDate
AND t.MyDateColumn < @endDate;
GO
But, I gotta say that running this for a full month by 'looping' on each date is not the right way to solve the problem. If you posted the problem you are trying to solve - it might be easier for us to recommend a better solution than looping.
Jeffrey Williams
“We are all faced with a series of great opportunities brilliantly disguised as impossible situations.”
― Charles R. Swindoll
How to post questions to get better answers faster
Managing Transaction Logs