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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL question

Status
Not open for further replies.

wuah

Programmer
Mar 15, 2001
42
DK
I don't know if this is the right forum, but here goes.

Is it possible to match/compare two sql-queries?

I have an SQL-query which includes some "Or" statements and another which includes some "AND" statements.
I'm quering in the same table in the same db, but I really want to get one output where I get the intersection between query 1 and 2. You can sort of say "3 = 1 AND 2". Get m drift?

Some somewhat a beginner in this SQL stuff so I don't know if all this can be described in one SQL-query?

Thanks

Rasmus
 
Sounds like what you need is a JOIN of two views -- the first created with query1, and the second with query2.

If you post up an example of what you tried, and the results you are after, I'm sure one of us could help you out further.

:)
Paul Prewett
penny.gif
penny.gif
 
Here you go: ;-)

strSQL = "SELECT * FROM tblCBtest WHERE (cb = " & Request.Form("Typen") & ") OR (cb2 = " & Request.Form("Typen") & ") OR (cb3 = " & Request.Form("Typen") & ") AND ( "
strSQL = strSQL & " (Amt LIKE '" & strAmt & "')"
strSQL = strSQL & " AND (Postnr LIKE '%" & strPostnr & "%')"
strSQL = strSQL & " AND (Byen LIKE '%" & strByen & "%')"
strSQL = strSQL & " AND (Navn LIKE '%" & strNavn & "%'))"
 
Which comes from this (which is cause to my first question):

strSQL = "SELECT * FROM tblCBtest WHERE"

strSQL = strSQL & " (cb LIKE '" & strTypen & "')"
strSQL = strSQL & " or (cb2 LIKE '" & strTypen & "')"
strSQL = strSQL & " or (cb3 LIKE '" & strTypen & "')"

'-------------------
str2SQL = "SELECT * FROM tblCBtest WHERE"

str2SQL = str2SQL & " (Amt LIKE '" & strAmt & "')"
str2SQL = str2SQL & " AND (Postnr LIKE '%" & strPostnr & "%')"
str2SQL = str2SQL & " AND (Byen LIKE '%" & strByen & "%')"
str2SQL = str2SQL & " AND (Navn LIKE '%" & strNavn & "%')"


=============

Greetings...
 
Your first solution, where you combined them together looks fine to me... is it causing an error of some sort?

penny.gif
penny.gif
 
Yes:

Microsoft OLE DB Provider for ODBC Drivers error '80040e07'

[Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression.

/marathon/resultspage3.asp, line 46

I'm not quite sure if it is the SQL that causes the fault, but I have a suspicion ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top