SpiderAxiom
12-27-2006, 12:10 PM
Hi Everyone,
I need some sql help. I am currently using this query:
<%
'***********************************************************************
p = Replace(Request("p"), "'", "''")
Set Connection = Server.CreateObject("ADODB.Connection")
Connection.Open "DSN=testpub; UID=wa"
Set RS = Server.CreateObject("ADODB.Recordset")
SQLS = "SELECT DISTINCT C.c, A.cart "
SQLS = SQLS & "FROM A, B, C "
SQLS = SQLS & "WHERE A.cart like '" & p & "' "
SQLS = SQLS & "AND A.cart = B.Xp "
SQLS = SQLS & "AND B.rel_ID = C.rel_ID "
SQLS = SQLS & "ORDER BY cart "
RS.CursorLocation = 3
RS.CursorType = 0
RS.ActiveConnection=Connection
RS.Open SQLS
'***********************************************************************
%>
It works great but I am trying to join two tables since the data is redundant. A.cart is the same data as C.c (after some relationships - see below). The strange thing is this query works sometimes, so I know I'm close. Does anyone know where i went wrong?
<%
'***********************************************************************
p = Replace(Request("p"), "'", "''")
Set Connection = Server.CreateObject("ADODB.Connection")
Connection.Open "DSN=testpub; UID=wa"
Set RS2 = Server.CreateObject("ADODB.Recordset")
SQLS2 = "SELECT DISTINCT C.c, A.cart "
SQLS2 = SQLS2 & "FROM A "
SQLS2 = SQLS2 & "INNER JOIN B "
SQLS2 = SQLS2 & "ON A.cart = B.Xp "
SQLS2 = SQLS2 & "INNER JOIN C "
SQLS2 = SQLS2 & "ON C.rel_ID = B.rel_ID "
SQLS2 = SQLS2 & "WHERE C.c like '" & p & "' "
SQLS2 = SQLS2 & "ORDER BY cart "
RS2.CursorLocation = 3
RS2.CursorType = 0
RS2.ActiveConnection=Connection
RS2.Open SQLS2
'***********************************************************************
%>
Classic ASP:
<%
CurrentRecord = 0
Do While CheckRS(RS) AND CheckRS(RS2)
%>
<% Response.Write ("RS Cart:") %>
<%= RS("c") %>
<% Response.Write ("<BR><BR>") %>
<% Response.Write ("RS2 Cart:") %>
<%= RS2("cart") %>
<% Response.Write ("<BR><BR>") %>
<%
RS.MoveNext
RS2.MoveNext
CurrentRecord = CurrentRecord + 1
Loop
%>
Any suggestions would be appreciated...Thanks
I need some sql help. I am currently using this query:
<%
'***********************************************************************
p = Replace(Request("p"), "'", "''")
Set Connection = Server.CreateObject("ADODB.Connection")
Connection.Open "DSN=testpub; UID=wa"
Set RS = Server.CreateObject("ADODB.Recordset")
SQLS = "SELECT DISTINCT C.c, A.cart "
SQLS = SQLS & "FROM A, B, C "
SQLS = SQLS & "WHERE A.cart like '" & p & "' "
SQLS = SQLS & "AND A.cart = B.Xp "
SQLS = SQLS & "AND B.rel_ID = C.rel_ID "
SQLS = SQLS & "ORDER BY cart "
RS.CursorLocation = 3
RS.CursorType = 0
RS.ActiveConnection=Connection
RS.Open SQLS
'***********************************************************************
%>
It works great but I am trying to join two tables since the data is redundant. A.cart is the same data as C.c (after some relationships - see below). The strange thing is this query works sometimes, so I know I'm close. Does anyone know where i went wrong?
<%
'***********************************************************************
p = Replace(Request("p"), "'", "''")
Set Connection = Server.CreateObject("ADODB.Connection")
Connection.Open "DSN=testpub; UID=wa"
Set RS2 = Server.CreateObject("ADODB.Recordset")
SQLS2 = "SELECT DISTINCT C.c, A.cart "
SQLS2 = SQLS2 & "FROM A "
SQLS2 = SQLS2 & "INNER JOIN B "
SQLS2 = SQLS2 & "ON A.cart = B.Xp "
SQLS2 = SQLS2 & "INNER JOIN C "
SQLS2 = SQLS2 & "ON C.rel_ID = B.rel_ID "
SQLS2 = SQLS2 & "WHERE C.c like '" & p & "' "
SQLS2 = SQLS2 & "ORDER BY cart "
RS2.CursorLocation = 3
RS2.CursorType = 0
RS2.ActiveConnection=Connection
RS2.Open SQLS2
'***********************************************************************
%>
Classic ASP:
<%
CurrentRecord = 0
Do While CheckRS(RS) AND CheckRS(RS2)
%>
<% Response.Write ("RS Cart:") %>
<%= RS("c") %>
<% Response.Write ("<BR><BR>") %>
<% Response.Write ("RS2 Cart:") %>
<%= RS2("cart") %>
<% Response.Write ("<BR><BR>") %>
<%
RS.MoveNext
RS2.MoveNext
CurrentRecord = CurrentRecord + 1
Loop
%>
Any suggestions would be appreciated...Thanks