473,395 Members | 1,466 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

SQL WHERE Multiple Columns

2
Hi People

This database stuff is new to me and it's driving me nuts! I hope someone can help me with this problem? I'm posting to this forum because looking at the posts, it looks like there are some knowledgeable people around here.

Hello by the way - I'm stressed and forgetting my manners!

I have a table called tbl_dir_details. Within that table I have 3 fields (well actually many more but they don't come into this equation). Those 3 fields are called Category, Category2 and Category3. I want to retrieve all records where ? is in any of the fields (? being a value passed via a URL parameter).

I have tried the following without luck:

SELECT *
FROM tbl_dir_details
WHERE Category = ? OR Category2 = ? OR Category3 = ?

I get the following error:
No value given for one or more required parameters

Now this works if I lookup one field at a time. It's like the value of ? is not being passed from one query to the next in the WHERE statement. Your going to cringe when I tell you that I have currently created 3 record sets to fudge this at the moment.

I hope i'm explaining that correctly?? So, does anyone here know what I’m going on about and secondly, know the correct syntax that I need to use?

Many thanks

Lee
Jul 4 '08 #1
1 1913
Stewart Ross
2,545 Expert Mod 2GB
Hi Lee, and welcome to Bytes!

The error message is a bit confusing. The syntax you used with the question marks is the same as that used with Activex Data Objects (ADO) recordsets to refer to variable parameters passed to the recordset - so it expects to find a parameter declared somewhere to match the wildcard character in the SQL. It is not the same parameter when it is repeated, it is different parameters from a list matched by position.

If, on the other hand, your comparison fields are strings set to the value '?' you need to enclose the value in single quotes, like this:

Expand|Select|Wrap|Line Numbers
  1. category = '?' OR category2 = '?' ...
If you do have parameters passed via ADO, rather than string values, the problem is as mentioned that it is expecting a different parameter on each occasion, with positional matching to each parameter defined.

I would suggest in this case that you use VB variables in place of the parameter and refer to the variable's value instead.

This is like this:

Expand|Select|Wrap|Line Numbers
  1. Dim somevar as string
  2. ...
  3. somevar = yourparameter
  4. ...
  5. where category = somevar or category2 = somevar...
You don't give enough information about how you are retrieving your parameter passed to the routine for me to advise further on how you set the variable at this stage.

-Stewart
Jul 4 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Nikola Pecigos | last post by:
Hi, I have the following problem: We have an Oracle 9.2 with one table "document" which contains a path to the filesystem. If I want to index these files (HTML, PDF, World, Excel, etc.), I...
4
by: Bob Hotschins | last post by:
I've joined several columns from several tables, and I would like to perform a relevance match against these multiple columns. It looks something like this: SELECT * FROM table1 LEFT JOIN...
6
by: Dennis | last post by:
In CSS3 it looks like we'll have multiple column flowing of text (newspaper style) in which the number of columns can be determined automatically given the available horizontal space....
7
by: Billy Jacobs | last post by:
I am using a datagrid to display some data. I need to create 2 header rows for this grid with columns of varying spans. In html it would be the following. <Table> <tr> <td colspan=8>Official...
4
by: carl.barrett | last post by:
Hi, I have a list box that displays 2 columns. Behind it sits a query with five columns. These are Column1 (DOB), column2 (a concatenated string of Surname Forname, Title), Column3 (Surname),...
5
by: Lie | last post by:
Hi all, I have problem in getting selectedindex of multiple listbox selection in a datagrid. I have a listbox with multiple selection mode inside datagrid. In Edit mode, I need to get back all...
2
by: BF | last post by:
Hi, I have some tables where I import data in, lots of field have gotten a NULL value which the application can not handle. Now can I replace each NULL value with '' in a columns with: update...
7
by: =?Utf-8?B?TG9zdEluTUQ=?= | last post by:
Hi All :) I'm converting VB6 using True DBGrid Pro 8.0 to VB2005 using DataGridView. True DBGrid has a MultipleLines property that controls whether individual records span multiple lines. Is...
2
by: ray well | last post by:
i need to display 2 columns of data in a list box. how would i set this up IN CODE. say my table is tblNames, and i have 2 fields, FirstName, LastName, and want the data to show up in 2...
3
by: Will | last post by:
Can someone help with code to delete multiple columns from an excel spreadsheet? I know which columns I need to delete. The code below will delete a single column but I'm not sure how to delete...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.