
March 4th, 2003, 08:39 AM
|
|
Registered User
|
|
Join Date: Feb 2003
Posts: 2
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
SQL to match 1 table's info with another table
<%<br> strconn = Server.MapPath("Coord_Login.mdb")<br> set conn=server.createobject("adodb.connection")<br> <br> conn.open "Provider = SQLOLEDB; data source = m308-srv;" _<br> & "Initial catalog = Coord_Login; user ID=gsi; password=gsi; " _<br> & "connect timeout = 30;"<br> <br> set rs = server.createobject("adodb.recordset")<br> rs.activeconnection = conn<br> <br> dim n<br> n=1<br> dim QueryString(0)<br> QueryString(0) = "IAP_Request.Sem=Student_info.sem"<br> 'QueryString(1) = "IAP_Request.Race=Student_info.race"<br> <br> SQL = "SELECT * FROM IAP_Request where Status='Approved'"<br> rs.Open SQL<br> Dim setWhere <br> Dim gotLastString,i<br> tempstr = "SELECT Student_info.Postal_code,Student_info.gender,Stude nt_info.Name,IAP_Request.Comp_name from Student_info,IAP_Request"<br> <br> <br>'do while not rs2.EOF <br> <br> do while not rs.EOF<br> Response.Write("Companies approved")<br> Response.Write(rs.Fields("Comp_name").value)<br> Response.Write("////")<br> <br> Response.Write(tempstr)<br> 'Response.Write("///")<br> 'Response.write(rs2.Fields(3))<br> <br> rs.MoveNext<br> Loop<br> <br> if not rs.EOF then<br> For i=0 to UBound(QueryString)<br> <font style="color:990000;">if (rs.Fields("Sem").value <> "Nil" and rs.fields("Sem")<>"" and setWhere=false) then<br> tempstr = tempstr & " WHERE " & QueryString(i)<br> setWhere = true<br> gotLastString = true<br> <br> <br> <br> elseif (rs.Fields("Sem").Value<>"Nil" and rs.fields("Sem")<>"" and gotLastString=true) then<br> tempstr = tempstr & " AND " & QueryString(i)<br> gotlaststring = true<br> end if<br> next</font> end if<br> set rs2 = server.createobject("adodb.recordset")<br> rs2.activeconnection=conn<br> rs2.Open tempstr<br> <br> do while rs2.eof <> true<br> 'for i=0 to rs2.Fields.Count-1<br> Response.Write(rs2.Fields(3).value)<br> 'Next<br> rs2.movenext<br> loop<br> <br> <br> rs.Close<br> set rs2=nothing<br> set rs=nothing<br> set conn=nothing<br> <br>%><br><br><font style="color:800080;">I think there's some problems with my SQL coz my 1st SQL is supposed to have only 3 members fitting the criteria so the 2nd SQL should only be processing 3 members but my 2nd SQL is not picking up just the 3 members from the 1st RS but processing all the members fitting the 2nd SQL,HELP!</font>
|