473,394 Members | 1,671 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,394 software developers and data experts.

SQL statement for Search Page

(Windows 2000 Server SP4 running ASP web pages with a Microsoft Access database)

Hi, I’m a newb just trying to get some help with an Access database SQL statement…

I’ve been trying to add a feature to an existing search page but I’m not having much luck with modifying the SQL statement to get it to work. The existing webpage searches a photo album database. You can search by people (keywords) and categories (places, events, trips, etc). All I’m trying to do is make it to where the album can be optionally searched by a pair of people / keywords (i.e. Find all photos with Bob & Sue in them).

To do this I’ve added a new menu with the name of “mnu_keywordList2” which has the exact values available of the original “mnu_keywordList” and default values of “%” which means the menu was left at a default setting of “Any”.

Here’s the existing SQL statement (simplified):
Expand|Select|Wrap|Line Numbers
  1. SELECT DISTINCT Pictures.PicRegDate, Pictures.PicFilename, Pictures.PicId, Pictures.PicDate,  edit AS [ThumbWebPath],      edit AS [ImageAltTag], edit AS [WebSourceImgPath]
  2.  
  3. FROM (Pictures  LEFT JOIN Attributes ON Pictures.PicId=Attributes.PicId)  LEFT JOIN KeyWords ON Pictures.PicId=KeyWords.PicId
  4.  
  5. WHERE (Attributes.Data LIKE 'mnu_ValueList' Or ('mnu_ValueList'='%' And Attributes.Data Is Null)) AND ((KeyWords.Keyword LIKE 'mnu_keywordList') Or ('mnu_keywordList'='%' AND KeyWords.Keyword Is Null))   AND (YEAR(Pictures.PicDate) BETWEEN 'txtDateRngBegin' AND 'txtDateRngEnd')
  6.  
  7. ORDER BY Pictures.PicDate
  8.  
At first I thought this was going to be a simple change of the WHERE clause and tried variations on the WHERE statement to the effect of:
Expand|Select|Wrap|Line Numbers
  1. WHERE (Attributes.Data LIKE 'mnu_ValueList' Or ('mnu_ValueList'='%' And Attributes.Data Is Null)) AND ((KeyWords.Keyword LIKE 'mnu_keywordList' AND 'mnu_keywordList2') Or (('mnu_keywordList'='%' AND 'mnu_keywordList2'='%') AND KeyWords.Keyword Is Null))   AND (YEAR(Pictures.PicDate) BETWEEN 'txtDateRngBegin' AND 'txtDateRngEnd')
  2.  
Now I’m guessing the table formed is going to have to be changed but wanted to make sure before I from scratch. In any case, I’d appreciate any help I can get!
Nov 8 '06 #1
8 1844
NeoPa
32,556 Expert Mod 16PB
Nicely posted question - I wish they were all as clearly defined.
Firstly, I don't understand the 'edit AS ...' stuff but I'll comment on parts of the WHERE clauses.
Specifically the LIKE construct.
LIKE expects a wildcard in the comparison which seems to be missing from your code.
In Access it uses '*'; In MS SQL it uses '&' (I think) and in Excel (MS Query) it expects '%'.
So, for instance, in Access
Expand|Select|Wrap|Line Numbers
  1. WHERE (Attributes.Data LIKE 'mnu_ValueList' Or ...
should be something like
Expand|Select|Wrap|Line Numbers
  1. WHERE (Attributes.Data LIKE 'BlahBlah*' Or ...
or
Expand|Select|Wrap|Line Numbers
  1. WHERE (Attributes.Data LIKE '*BlahBlah*' Or ...
I've also just noticed that the SQL doesn't seem to have the resolved value in the comparison.
I don't know how you create this SQL, so I can't post a correction, but this seems to be comparing the data against a string which is the name of the variable, rather than against the contents of it.

I hope this helps - repost where you understand to if you still have problems.
Nov 8 '06 #2
Nicely posted question - I wish they were all as clearly defined.
Firstly, I don't understand the 'edit AS ...' stuff but I'll comment on parts of the WHERE clauses.
Ha-ha, thanks. The edits are just where I was removing some long unrelated static information that got concatenated to form the ThumbWebPath and ImageAltTag variables for images on the page (stuff like filenames and directory path info).

Specifically the LIKE construct. LIKE expects a wildcard in the comparison which seems to be missing from your code. In Access it uses '*'; In MS SQL it uses '&' (I think) and in Excel (MS Query) it expects '%'.
I guess the LIKE calls in this are just bad form but all they are really doing are string comparisons. For instance:

'mnu_keywordList' might be the user selected value, “Doe, John” and it’s trying to match that to a value listed in KeyWords.Keyword. All of this works fine. It didn’t fail until I started editing ha-ha. I was just trying to make it look for the two keywords as a pair; if the user selects that option.
Nov 8 '06 #3



The picture above is how the search page would look. All selections are optional but this particular search would result in all pictures of "Adams, Jane" and "Adams, John" together during Christmas.

I'm just asking how to accomplish this. The way it's setup now you can't search for a pair of people / keywords, only one person / keyword. Is it possible to accomplish this via a WHERE clause or does the entire statement have to be rewritten?
Nov 8 '06 #4
I've also just noticed that the SQL doesn't seem to have the resolved value in the comparison.
I don't know how you create this SQL, so I can't post a correction, but this seems to be comparing the data against a string which is the name of the variable, rather than against the contents of it.
To answer this do you mean what value do I expect to be returned in the end? Meaning the final returned value from a user’s search? If so, that value would be a table of rows that have the matching criteria. Those rows would contain image data that a “results ASP page” will use to display the matching images, most of the time, via thumbnail images in a 4 x 3 grid layout. From there the resulting thumbnail images are loaded with all sorts of JavaScript to pull up more detailed descriptions and links to full size images, etc. It’s really just a searchable photo album.
Nov 8 '06 #5
NeoPa
32,556 Expert Mod 16PB
This is probably academic as you say the SQL works for you fundamentally, but no, I was commenting on the SQL you have posted above.
From my reading of it - it will not compare the recordset data with the value in 'mnu_ValueList' (as one example) as I would assume you intend, but rather with the actual string "mnu_ValueList" itself.
Nov 9 '06 #6
This is probably academic as you say the SQL works for you fundamentally, but no, I was commenting on the SQL you have posted above.
From my reading of it - it will not compare the recordset data with the value in 'mnu_ValueList' (as one example) as I would assume you intend, but rather with the actual string "mnu_ValueList" itself.
Ah, there’s a string request before the SQL statement to handle that. It works. It does an error check and sets a default in case the variable isn’t returned from the form for whatever reason.

i.e. mnu_keywordList = Request.QueryString("mnu_keywordList")
Nov 9 '06 #7
I think we’re just getting caught up on form & semantics. I’ll worry about that later. I’m just after the best approach to the problem at hand.

------------------------

There are three tables being referenced in this call. Each table has a common element and that’s the PicId. Every photo has a unique PicId. ...and there are about 14,000 PicId's at the moment.

Pictures Table Data
This is the most obvious data. Each row is a different picture with a unique PicId. For every row / PicID there is picture data such as Filename, Description, PicDate, Registered Date (date entered into database), PicSource and a thumbnail image, etc.

KeyWords Table Data
This table is a listing of every keyword that applies to any given photo. In this case the keywords are people’s name. There will be a separate line for every keyword and so there can be multiple lines with the same PicID. That’s because photos can have one or more keyword / people pictured in them.

Attributes Table Data
This table is laid out in the same form as the KeyWords table except that instead of tracking keywords / people it’s tracking broad categories such as Events, Holidays, Special Occasions, trip names, etc.
Nov 9 '06 #8
NeoPa
32,556 Expert Mod 16PB
I'm not sure that I can help you Bosnoval.
If I see something I think might cause problems then I post.
Or if I see a (generally straightforward) solution to a problem also.
That bit of the SQL I mentioned is what I thought I could help with...
Sorry.
Nov 9 '06 #9

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

Similar topics

11
by: Jeff Sandler | last post by:
I need a MySQL select statement as part of a PHP script. I want to find rows where a certain column either starts with or equals a user-supplied string. The string will be 1 or more characters in...
22
by: Alan | last post by:
I have many OR in the if statement, any method to simplify? if (val == 5 | val == 9 | val == 34 | val == 111 | val == 131 | .......) // .... thank you
5
by: WindAndWaves | last post by:
Hi Team The function below searches all the tables in a database. However, if subsearch = true then it searches all the objects listed in a recordset (which are all table names). I thought to...
3
by: Andy_Khosravi | last post by:
I have been trying to build a user friendly search engine for a small database I have created. I'm having some particular problems with one of my date fields. Here's the setup: I'm using...
1
by: washoetech | last post by:
Hello, I have a search box on my web app that I want to search several tables in my SQL 2000 DB. I have set up a full text catalog for indexing. The following Select statement works perfectly...
3
by: Don | last post by:
I've added a Setup and Deployment project to my Visual Studio 2005 Windows Application solution and have several OCX and DLL files that will be installed. But I can't seem to find any examples in...
6
by: jej1216 | last post by:
I am trying to put together a PHP search page in which the user can select none, one, two, or three fields to search, and then the results php will build the SQL with dynamic where caluses to reflect...
8
by: jasone | last post by:
Hi all, im nearly there with this one and im sure it shouldnt be hard to solve, i just cant seem to find the solution. ive got records being displayed, the user can then tick what records to...
1
adelemb
by: adelemb | last post by:
Hi, I'm trying to make a SQL statement work and am getting quite mixed up with it, I hope someone can help! I have a form with a textbox named "keyword". I want the user to enter a keyword and...
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
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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.