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

What's wrong with my SELECT statement?

Status
Not open for further replies.

ElEye

IS-IT--Management
Nov 17, 2001
187
US
Here's what I wrote:

strsql = ""
strsql = "SELECT * from [Table1] WHERE "
strsql = strsql & " [Column1] NOT in ('abc','def','ghi')"
strsql = strsql & " AND [Column2] = " & variable1
strsql = strsql & " OR [Column3] = " & variable1
strsql = strsql & " OR [Column4] = " & variable1
strsql = strsql & " ORDER BY [Column5] ASC"

The results I get are as if the statement said:

strsql = ""
strsql = "SELECT * from [Table1] WHERE "
strsql = strsql & " [Column2] = " & variable1
strsql = strsql & " OR [Column3] = " & variable1
strsql = strsql & " OR [Column4] = " & variable1
strsql = strsql & " ORDER BY [Column5] ASC"

What am I doing wrong?

TIA,

Dave [idea]
[]
 
Have you tried Response.Write'ing the statment to the screen and then pasting it into your database query analyzer to see what it does in there?

-T

01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111
The never-completed website:
 
I'm sorry, I should have done so. Here's the response:

SELECT * from [Table1] WHERE [Column1] NOT in ('abc','def','ghi') AND [Column2] = 'variable1 result' OR [Column3] = 'variable1 result' OR [Column4] = 'variable1 result' ORDER BY [Column5] ASC

It sure looks like it's doing what I want, but the data is not.

TIA,

Dave [idea]
[]
 
SOLVED!

Please note the parans:

strsql = ""
strsql = "SELECT * from [Table1] WHERE"
strsql = strsql & " ([Column1] NOT in ('abc','def','ghi'))"
strsql = strsql & " AND ([Column2] = " & tkey
strsql = strsql & " OR [Column3] = " & tkey
strsql = strsql & " OR [Column4] = " & tkey
strsql = strsql & ") ORDER BY [Column4] ASC"

Dave [idea]
[]
 
Ah...see now if I had asked about that we would have had it solved earlier, but I didnt make the connection earlier :p

Sorry about that,
-T

01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111
The never-completed website:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top