-
Query statement assistance
I am new to SQL so please bare with me.
What I am tring to achieve is a SQL query that displays results based on one category in which the rest of the query will display results based on the initial category or group. The initial category is a drop down box. Then from there I created a navigation menu with radial button in which refines the search.
For example this is the drop down selections:
dim unitquery as string
if (unit.text = "ALL Model Years" ) then
unitquery = "[Auto_year] BETWEEN" & chr(39) & "1970" & chr(39) & "AND" & chr(39) & "2005" & chr(39)
else if (unit.text = "Mustang Only" )
unitquery = "[model]= 'Mustang' "
else if (unit.text = "Ranger Only" )
unitquery = "[model]= 'Ranger' "
else if (unit.text = "Ranger Only" )
unitquery = "[model]= 'Explorer' "
End if
strSearch = gen.Text
dbcommand = New SqlDataAdapter( "SELECT model, color, engine, navgtn_sys, timestamp " _
& "FROM tbl_name " _
& "WHERE ( " & unitquery & ") AND model LIKE '%" & Replace(strSearch, "'", "''") & "%'" _
& "OR color LIKE '%" & Replace(strSearch, "'", "''") & "%'" _
& "OR engine LIKE '%" & Replace(strSearch, "'", "''") & "%'" _
& "OR navgtn_sys LIKE '%" & Replace(strSearch, "'", "''") & "%'",bcon )
What happens is the farther the query is refined it displays all models not just Mustang or Ranger. This is an example not the actual data I am seeking.
Any ideas where I can improve on this query string to seperate the queries by model as the search is refined?
-
I think the problem you're having is that your OR statements are causing you to pick up any model because they are being evaluated in conjunction with your AND statement. In other words, if the unitquery condition is true and any of the conditions that follow it are true, a row is returned.
If you need help fixing this post a follow-up.
Paul
~~~~
Microsoft MVP (Visual Basic)
-
Thanks for the response, unfortunately I an very new to SQL and i have tried various other combinations of this query string with no luck. What could I use instead of "OR"? Should I incorporate more "if else" statements?
-
It seems like all of your "OR"s should be "AND"s...
Bob Rouse
Dimension Data
-
It appears I figured it out..
Thank you for your assistance gentleman!
-
So what was it? Enquiring minds want to know...
Bob Rouse
Dimension Data
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks