Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Skip Loop

Status
Not open for further replies.

finkelman

Programmer
Mar 17, 2002
5
US
Hi,

I have the following question.

I have 2 tables. When I am looping through the records from table1, I would like to have it check within table2, if the "hide" field in table 2 for the current record is set to "1", it should skip this record and move on to the next. I know I can probably do a left join, but the problem is that not all the records that are in table 1 are in table 2. Only a select few.

I have the following code.

<% sql_select_Accessory = &quot;SELECT Accessory_Line_Id, Sku, Accessory_Item_Id, Accessory_Item_Name, Accessory_Item_Sku FROM Store_items_accessories WHERE Store_id=&quot;&Store_id&&quot; AND Item_Id=&quot;&Item_Id %>
<% Set rs_select_Accessory = Server.CreateObject(&quot;ADODB.Recordset&quot;) %>
<% rs_select_Accessory.open sql_select_Accessory,conn_store,1,1 %>



<% rs_select_Accessory_Group.MoveFirst %>
<% Do While Not rs_select_Accessory_Group.EOF %>


<%

Item_Id = rs_select_Accessory_Group(&quot;Accessory_Item_Id&quot;)

sql_accessories2 =&quot;SELECT * FROM accs_pricing WHERE Item_Id=&quot;&Item
Set rs_store_check = Server.CreateObject(&quot;ADODB.Recordset&quot;)
rs_store_check.open sql_accessories2,conn_store,1,1

if not rs_store_check.eof then

hide = rs_store_check(&quot;hide&quot;)
if hide = -1 then
rs_select_Accessory_Group.MoveNext 'I added this, thinking this would do the trick.

end if

%>

Here would be the loop

<% rs_select_Accessory_Group.MoveNext %>
<% Loop %>

Please let me know if the question is understandable.

Thanks
Eli
 
as for the problem of not having all records in both tables. All your tables should have keys and foriegn keys to allow for relationships between them.

If you don't have any shared keys in these tables you need to make some and then you can do this easily.

if you do have them then just do a JOIN and only select the records from Table2 WHERE they are relivant to Table1

hope this helps
 
Is there any way for me to sompare the second database inside the loop, and to something like this:

hide = rs_store_check(&quot;hide&quot;)

if hide = -1 then
rs_select_Accessory_Group.MoveNext
end if

Will this skip this record and move on to the next?


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top