Access 2003 Databse
ASP.NET 2
Win 2003 Server
Currently I have a search page that only allows a single keyword (person) to be searched at a time. I thought upgrading that option via a multiple selection listbox would be better so that you can search for a pair or more of people at a time but the query that makes this happen is giving me a run for my money. I’m unsure as how to proceed and so I’m hoping someone can help me out.
My somewhat simplified query is as follows: -
-
SELECT DISTINCT Pictures.PicRegDate, Pictures.PicFilename, Pictures.PicId, Pictures.PicDate
-
-
FROM (Pictures LEFT JOIN Attributes ON Pictures.PicId=Attributes.PicId) LEFT JOIN KeyWords ON Pictures.PicId=KeyWords.PicId
-
-
WHERE (Attributes.Data LIKE @ddlValueList Or (@ddlValueList='%' 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)
-
-
-
ORDER BY Pictures.PicDate, Pictures.PicRegDate
-
-
“%” is a default value for both @ddlValueList and @mnu_keywordLis t which is just the value for a menu selection of “< Any >”. A typical runtime value for each might be “Birthday” for @ddlValueList and “Doe, John” for @mnu_keywordLis t. The resulting records would be all pictures of John Doe at a birthday.
I’m guessing my new search page is going to have to dynamically write portions of the query, like an AND statement or something for each keyword, but I’m not even certain the syntax for the query enough to be able to write out that block of code yet…
23 2781 nico5038 3,080
Recognized Expert Specialist
Hmm, I have no ASP .NET experience, but for querie constructions hat shouldn't bother. :-)
For multiple fields your approach will be OK, just use a LIKE and %
For a "full match" pass the entered string and for the <all> use %.
For muliple "full matches" you can construct an IN(a, b, c, ....) structure in the WHERE clause before passing the query to Access.
In Access I often use a (temp) help table with the distinct values for e.g. a lastname and a YesNo field. For the display of the result I use a JOIN of the original table with the temptable that's having a True criteria for the YesNo field.
Getting the idea ?
Nic;o)
NeoPa 32,569
Recognized Expert Moderator MVP
Personally, I'd go for the In() structure where possible. Unfortunately it doesn't handle multiple Like entries though. This is where Nico's TempTable idea really helps (You could just build a more complicated SQL string here with multiple ORs instead). His solution is better overall as it's more scalable and better handles large numbers of these criteria. Another alternative is to use SubQueries in place of the TempTable. It has the benefit of handling the whole query in a single SQL string. (More on SubQueries can be found in Subqueries in SQL.)
Ah, thanks for the IN() tips. That helps a lot. Using that I could loop through the “selected” listbox items and write them into the IN() statement like the two names below: -
-
SELECT DISTINCT Pictures.PicRegDate, Pictures.PicFilename, Pictures.PicId, Pictures.PicDate
-
-
FROM (Pictures LEFT JOIN Attributes ON Pictures.PicId=Attributes.PicId) LEFT JOIN KeyWords ON Pictures.PicId=KeyWords.PicId
-
-
WHERE KeyWords.Keyword IN ('Doe, John', 'Doe, Jane')
-
-
ORDER BY Pictures.PicDate, Pictures.PicRegDate
-
-
By the temp table and/or sub-query do you mean as a way to generate exclusive searches? For example the above query actually doesn’t generate the results I’m after. It essentially searches for the two names separately and then joins the total results. Instead I really only want to return results where BOTH people are pictured (pictures with only one or the other person shouldn’t be in the result).
nico5038 3,080
Recognized Expert Specialist
With multiple rows for one picture you would need to switch to using a GroupBy query.
Use the "IN() query" as a basis for that and use Count() in the GroupBy query with imageID as the grouping field. The Count() field can be tested for >1 to get only multiple hits.
Getting the idea ?
Nic;o)
…again thanks for the help! It’s very much appreciated.
Hmm, well I get that two or more fields in the IN(test1, test2) query could produce the same record multiple times. …and that only image records that do are the records I’m after.
What I don’t understand is how to count the PicId’s in a useful way. Once the IN() comes back with the records wouldn’t the DISTINCT already keep me from having duplicate PicId’s. A count(KeyWords. PicId) would only result in a literal count of how many records I have wouldn’t it? I can’t think of a way to count(PicId) where the count would result in a count of how many times that particular unique PicId / record row was in the records as apposed to it just returning a .recordcount equivalent for the total number of rows in the result.
The only way I can think of implementing this would possibly be with a sub-query???
nico5038 3,080
Recognized Expert Specialist
The Group By PictureID will give a count per PictureID.
When you remove the "Group By PictureID" you'll get just a count of all records.
Just create a groupby and see the effect of adding / removing fields.
It's the used number of fields that will give the granularity. The more fields in the grouping the lower the count in general.
Distinct will just remove duplicates, but not count the number if dupes.
Nic;o)
NeoPa 32,569
Recognized Expert Moderator MVP
Bosnoval,
This is quite advanced logic and I can only say, Nico seems to have a good handle on it. Trust him as he's shown good understanding of this issue. This is a very neat trick to keep in your arsenal :) If you get stuck come back for help, but be assured, this concept is a very good one.
Oh, I’m not doubting the concept I’m just saying I’m having trouble understanding it ha-ha. I guess my issue is that when trying to test this so that I can better understand it I’m getting errors. I’m trying something like this: -
SELECT Pictures.PicRegDate, Pictures.PicFilename, Pictures.PicId, Pictures.PicDate
-
-
FROM (Pictures LEFT JOIN Attributes ON Pictures.PicId=Attributes.PicId) LEFT JOIN KeyWords ON Pictures.PicId=KeyWords.PicId
-
-
WHERE KeyWords.Keyword IN ('Doe, John', 'Doe, Jane') AND YEAR(Pictures.PicDate) BETWEEN 1900 AND 2007
-
-
GROUP BY Pictures.PicId
-
-
ORDER BY Pictures.PicDate, Pictures.PicRegDate
-
I’ve also tried changing the GROUP BY to KeyWords.PicId but it gives the same error, “You tried to execute a query that does not include the specified expression 'PicRegDate' as part of an aggregate function.”
As far as the count() syntax goes for a GROUP BY I’ve been reading up on sites like “sql-tutorial.net” to understand what you mean. Altogether I think you’re suggesting a SQL query something like this below?? -
SELECT Pictures.PicRegDate, Pictures.PicFilename, Pictures.PicId, Pictures.PicDate, Count(Pictures.PicId)
-
-
FROM (Pictures LEFT JOIN Attributes ON Pictures.PicId=Attributes.PicId) LEFT JOIN KeyWords ON Pictures.PicId=KeyWords.PicId
-
-
WHERE KeyWords.Keyword IN ('Doe, John', 'Doe, Jane') AND YEAR(Pictures.PicDate) BETWEEN 1900 AND 2006
-
-
GROUP BY Pictures.PicId
-
-
ORDER BY Pictures.PicDate, Pictures.PicRegDate
-
This too gives the same error.
nico5038 3,080
Recognized Expert Specialist
Try: -
SELECT Pictures.PicRegDate, Pictures.PicFilename, Pictures.PicId, Pictures.PicDate, Count(Pictures.PicId)
-
-
FROM (Pictures LEFT JOIN Attributes ON Pictures.PicId=Attributes.PicId) LEFT JOIN KeyWords ON Pictures.PicId=KeyWords.PicId
-
-
WHERE KeyWords.Keyword IN ('Doe, John', 'Doe, Jane') AND YEAR(Pictures.PicDate) BETWEEN 1900 AND 2006
-
-
GROUP BY Pictures.PicRegDate, Pictures.PicFilename, Pictures.PicId, Pictures.PicDate
-
-
ORDER BY Pictures.PicDate, Pictures.PicRegDate
-
All fields in the SELECT part need to have an aggregate function (Count, Max, etc) or need to be present in the GROUP BY.
As I assume that all Picture fields are the same for every PictID, this GROUP BY should work.
Nic;o)
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Wolfgang Kaml |
last post by:
Hello All,
I have been working on this for almost a week now and I haven't anything up
my sleeves anymore that I could test in addition or change....
Since I am not sure, if this is a Windows 2003 Server or ADO or ODBC issue,
I am posting this on all of the three newsgroups.
That's the setup:
Windows 2003 Server with IIS and ASP.NET actiavted
Access 2002 mdb file (and yes, proper rights are set on TMP paths and path,
|
by: Dan V. |
last post by:
We use dot net, asp.net and iis 5 on a pentium 1.2 GHZ (dual capable - one
in now) and 1 MB RAM and Access 2002.
Our ASP.NET Database queries to MS Access (running locally) are very slow,
(the programmer can't change this)
and they take between 2 - 15 seconds to load a data page -this is even
running locally on the web server. There are multiple web sites on this
server, with not too much traffic.
Our goal is to have 100-200...
|
by: Joris Kempen |
last post by:
Hi people,
I know that the question has come around sometimes:
How to open an Access Report using ASP and export it to for example
RTF.
I'm trying to implement the first method of David Cline:
http://www.15seconds.com/issue/981216.htm
|
by: JustMe |
last post by:
I don't know if this has anything to do with AccessXP running on Terminal
Services with Access97/2000 also installed, but here is one example of a
query that does not work any longer:
SELECT DLookUp("MajorCategory","AutoTypes","='1'") AS
MajorCategory, PreOwned.PaintColor
FROM PreOwned;
When I try to run the above query I get the following error:
|
by: Yannick Turgeon |
last post by:
Hello,
We are in the process of examining our current main application. We have to
do some major changes and, in the process, are questionning/validating the
use of MS Access as front-end. The application is relatively big: around 200
tables, 200 forms and sub-forms, 150 queries and 150 repports, 5GB of data
(SQL Server 2000), 40 users.
I'm wondering what are the disadvantages of using Access as front-end? Other
that it's not...
| |
by: baramee |
last post by:
I develop web application by asp.net with ms access.
In general , it work fine.
But if hit rate of web is very much, it occure error 'Unspecified error'.
it error on conn.open.
My code will be closed and destroyed connection object always.
I think that problem come from database concurrency.
I can't change database to sql server because it about budget.
How can i fix this error?
Thanks in advance.
|
by: DaveG |
last post by:
Hi all
I am planning on writing a stock and accounts program for the family
business, I understand this is likely to take close to 2 years to
accomplish. The stock is likely to run into over a thousand items and
the accounting side will be used for hopefully many years so the
entries are likely to be vast.
The delema is what is best to use ase the DB engine, Access I have as
part of Office 2002 or should I really be looking at SQL...
|
by: Steve |
last post by:
One of our clients recently upgraded their Office version to 2003. When
they tried to run our program (written in Access 2000), they ended up
with the wrong data. My coworker and I have tested this problem and
found that it ONLY occurs on Windows XP machines running Office 2003.
The problem ends up being that ONE 1-to-1 join in ONE query within the
application does not perform as a 1-to-1 join. It acts as though there
is no join at all....
|
by: smaczylo |
last post by:
Hello, I've recently been asked to work with Microsoft Access, and
while I feel quite comfortable with Excel, I'm at a complete loss with
databases. If someone could help me with this issue I'm having I'd be
most appreciative. The database is already constructed, I'm just
wanting to export the data to an excel file.
In short, I'm hoping to export two Tables (or queries...not sure which
to use - they both seem to have the same data) in...
|
by: NeoPa |
last post by:
Many of us have noticed that there are some very useful functions available to you when using Excel, but these same functions are not available, as standard, in Access.
A particular issue I had recently (and I know others have come across this recently too) is rounding up and down. I know the Excel ROUNDUP() function rounds away from zero rather than upwards specifically, but is still useful in most circumstances.
To allow an Access...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |