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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 using For/Next with an sql statement

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-02-08 : 10:12:27
gerry writes "I'm trying to replace the following

SELECT ID FROM AvailDates WHERE 'Inputdate1' >= Adate1 AND 'Inputdate2'
<= Adate2 OR 'Inputdate1' >= Adate2 AND 'Inputdate2'<= Adate3 OR
'Inputdate1' >= Adate3 AND 'Inputdate2' <= Adate4 OR 'Inputdate1' >=
Adate4 AND 'Inputdate2'<= Adate5

with the following looping statement.
9Wherever I put the for/next loop it doesn't work as an OR statement. I just
get results for n=4 or errors0


Dim n
set Recordset1 = Server.CreateObject("ADODB.Recordset")
Recordset1.ActiveConnection = MM_MySite_STRING
for n=1 to 4
Recordset1.Source = "SELECT ID FROM AvailDates WHERE '" +
Replace(Recordset1__Inputdate1, "'", "''") + "' >= Adate" & n & " AND '"
+ Replace(Recordset1__Inputdate2, "'", "''") + "'<= Adate" & n+1 & " "
Next
Recordset1.CursorType = 0
Recordset1.CursorLocation = 2
Recordset1.LockType = 3
Recordset1.Open()
Recordset1_numRows = 0



Thanks"

Arnold Fribble
Yak-finder General

1961 Posts

Posted - 2002-02-08 : 12:28:01
I don't know ADO, but it looks to me like you're setting the recordset's source property to 4 different values and opening the recordset after setting it to the last one.


Go to Top of Page

bcollinson
Starting Member

9 Posts

Posted - 2002-02-08 : 12:34:22
You're looping through and setting the source for the recordset, but you're not actually retrieving any records until after you've exited the loop (n = 4).

Go to Top of Page
   

- Advertisement -