Link to home
Start Free TrialLog in
Avatar of dotnet0824
dotnet0824

asked on

convert to SQL Server loop

Hi,
I have this code which has to be written in SQL Server stored Proc . Basically stored proc accepts
StartDate and EndDate and Calcuates the days and loops thru the end of the date and runs the select statement .
   S = DateDiff("d", varStartDate, varEndDate - 1)
                If s > 0 Then
                    For i = 1 To s
                                          
                      Select * from tblBank where bankID = 1 and date = dateAdd("d",s,varstartdate)
                      and bankID = varbankID
Avatar of Kevin Cross
Kevin Cross
Flag of United States of America image

First let me suggest, you just do this with a normal query, but I will post a loop shortly:
(seems like you are adding a day at beginning and end, so you technically can just input startdate one day later and end date one day sooner -- but coded per loop above)
Select * 
from tblBank 
where bankID = @varbankID
and date between (@varstartdate+1) and (@varenddate-1)
-- and bankID = 1 /* commented this out as already filtering bankID */

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Kevin Cross
Kevin Cross
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dotnet0824
dotnet0824

ASKER

thanks a lot mwvisa.. I posted a query to add records to temp table if you could help.
You are welcome.