Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

SQL question

Posted on 2002-05-03
11
Medium Priority
?
173 Views
Last Modified: 2010-05-02
hi can someone please tell me why this statement will not work it works fine when just searching for subdom but will not when using AND Please advise...

Subdom = Request.QueryString("Subdom")
Domain = Request.QueryString("Domain")
Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset

   ' Open the connection
   cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
      "Data Source=" & App.Path & "\DDNSHCP.mdb;"
 
   ' Open the recordset
   rst.Open "SELECT * FROM Users WHERE Subdom = '" & Subdom & "' AND Domain = "' & Domain & "'", _
      cnn, adOpenKeyset, adLockOptimistic
0
Comment
Question by:hilltop
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
  • 2
  • +1
11 Comments
 
LVL 2

Author Comment

by:hilltop
ID: 6989522
This is being executed from a webclass
0
 
LVL 12

Expert Comment

by:roverm
ID: 6989641
Couple of possibilities:
1. Make sure the query isn't case sensitive:
SELECT * FROM Users WHERE UCase(Subdom) = '" & UCase(Subdom) & "' AND UCase(Domain) = "' & UCase(Domain) & "'" (I am not sure about the UCase in the SQL statement, could be Upper as well).
2. Use the LIKE statement instead of the '=':
SELECT * FROM Users WHERE Subdom LIKE '" & Subdom & "%' AND Domain LIKE "' & Domain & "%'" (make sure to add the percent sign '%')
3. Combine the first 2 options.

D'Mzzl!
RoverM  
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 6989671
rst.Open "SELECT * FROM Users WHERE Subdom = '" & Subdom & "' AND Domain = "' & Domain & "'", _
     cnn, adOpenKeyset, adLockOptimistic

Unless it is a typo you have the quotes backwards between Domain = and & Domain

Should be
rst.Open "SELECT * FROM Users WHERE Subdom = '" & Subdom & "' AND Domain = '" & Domain & "'", _
     cnn, adOpenKeyset, adLockOptimistic

If that is not the problem what error are you getting?  

If you are just not getting any records are you sure records exist for the criteria?

good luck
mlmcc
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 2

Author Comment

by:hilltop
ID: 6989882
No dice when using
rst.Open "SELECT * FROM Users WHERE Subdom = '" & Subdom & "' AND Domain = '" & Domain & "'", _
    cnn, adOpenKeyset, adLockOptimistic

It just pops up the microsoft script debugger no error other than that.

when using
rst.Open "SELECT * FROM Users WHERE Subdom = '" & Subdom & "'", _
      'cnn, adOpenKeyset, adLockOptimistic

it works fine I am at a serios loss here
0
 
LVL 2

Author Comment

by:hilltop
ID: 6989886
new development when using

rst.Open "SELECT * FROM Users WHERE Domain = '" & Domain & "'", _
      cnn, adOpenKeyset, adLockOptimistic

it errors as well this is a field in the Users table any ideas
0
 
LVL 2

Author Comment

by:hilltop
ID: 6989998
I renamed the field Domains and updated my app to reflect the new field name were applicable the AND statment now works fine. Do you have any idea why this happened
0
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 200 total points
ID: 6990453
Domain is a reserved word.
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 6990460
You could also have surrounded with square brackets [Domain]
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 6992705
You're right emoreau.  Seems like we overlook the obvious.

mlmcc
0
 
LVL 12

Expert Comment

by:roverm
ID: 6993088
Yeppers....Good one emoreau!
0
 
LVL 2

Author Comment

by:hilltop
ID: 6994098
Thank you very much
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

597 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question