473,320 Members | 2,094 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,320 software developers and data experts.

strSQL - Searching 2 Columns in Same Table?

Hi, Thanks for any help in advance...
The Problem - I have a search routine below, which works and
will return any result where the seach words is found in my DB
products.prodName, all good...

However i'd like it to also like to look at my
products.productDesc (at the same time) to see if the
description also has the word - anyone know how i can achieve
this?
strSQL = "SELECT * FROM products WHERE "
strSQL = strSQL & BuildSQL ("products.prodName",
sarySearchWord)

Function BuildSQL (strTable, sarySearchWord)
intSQLLoopCounter = 0

BuildSQL = BuildSQL & "(" & strTable & " LIKE '%" &
sarySearchWord(0) & "%'"

For intSQLLoopCounter = 1 To UBound(sarySearchWord)

If Request.QueryString("searchMode") = "allwords" Then
BuildSQL = BuildSQL & " AND "
else
BuildSQL = BuildSQL & " OR "
End if

BuildSQL = BuildSQL & strTable & " LIKE '%" &
sarySearchWord(intSQLLoopCounter) & "%'"
Next

BuildSQL = BuildSQL & ")"
End Function

----------------------------------------------
Posted with NewsLeecher v2.0 Beta 5
* Binary Usenet Leeching Made Easy
* http://www.newsleecher.com/?usenet
----------------------------------------------

Jul 22 '05 #1
1 1166
InvisibleMan wrote:
Hi, Thanks for any help in advance...
The Problem - I have a search routine below, which works and
will return any result where the seach words is found in my DB
products.prodName, all good...

However i'd like it to also like to look at my
products.productDesc (at the same time) to see if the
description also has the word - anyone know how i can achieve
this?
strSQL = "SELECT * FROM products WHERE "
strSQL = strSQL & BuildSQL ("products.prodName",
sarySearchWord)

Function BuildSQL (strTable, sarySearchWord)
intSQLLoopCounter = 0

BuildSQL = BuildSQL & "(" & strTable & " LIKE '%" &
sarySearchWord(0) & "%'"

For intSQLLoopCounter = 1 To UBound(sarySearchWord)

If Request.QueryString("searchMode") = "allwords" Then
BuildSQL = BuildSQL & " AND "
else
BuildSQL = BuildSQL & " OR "
End if

BuildSQL = BuildSQL & strTable & " LIKE '%" &
sarySearchWord(intSQLLoopCounter) & "%'"
Next

BuildSQL = BuildSQL & ")"
End Function


I haven't a clue as to what this query is. All i see is a bunch of vbscript
statements that I imagine are supposed to result in a string containing a
sql statement. Why not show us that instead?

Response.Write strSQL

Better yet:
1. Tell us what database type and version you are using
2. Show us some sample data (relevant fields only, please)
3. Show us the results you wish to obtain from the sample data
The operative word is "show". As in

field1 field1 field3
data data data
data data data
data data data
data data data

results:
field1 field1 field3
data data data
data data data

I strongly suggest you stop using dynamic sql for this.

Bob Barrows

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 22 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: jas | last post by:
> This is what I want to do with the data table below. > > I only want it to show one id for each issue. ( ie, 4001 only once, > 4002 only once, etc. But only the one with the latest date and...
10
by: sffan | last post by:
I am new to database programming and was curious how others solve the problem of storing encrypted in data in db table columns and then subsequently searching for these records. The particular...
10
by: Lauren Quantrell | last post by:
I have never written a trigger before and now am seeing the light. Is there a way to write a trigger so that if a user changes any column in a single row on one table then the trigger will write...
10
by: VA | last post by:
I got the following function to swap table columns from somewhere on the Internet function swapColumns (table, colIndex1, colIndex2) { if (table && table.rows && table.insertBefore && colIndex1...
5
by: David Wender | last post by:
I want to create a dataview with a sort on multiple columns. However, when I use FindRows, I only want to search some of the columns, not all. Is this possible? I have not been able to make it...
33
by: Geoff Jones | last post by:
Hiya I have a DataTable containing thousands of records. Each record has a primary key field called "ID" and another field called "PRODUCT" I want to retrieve the rows that satisy the following...
7
by: john | last post by:
In my form I have a master table and a details table linked 1xM. I can search through the whole parent table but I also like to be able to search through the child table fields to find parent...
5
by: ebernedo | last post by:
Hey guys, I'm new here and also pretty new to access I'm creating a database at work, and need to be able to search things within it to find the right part number in our case... heres a sample...
2
by: Eniacson | last post by:
I've worked with DB2 for a long time, but I'm new to the AS400 environment. I'm having a problem with an SQL statement that runs perfectly when I use STRSQL, but when I batch it and call...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.