Can anyone help with filtering records ended with "?".
here is the code I have tried: - strWhere = strWhere & "([stock_site] not like ""*" & "'?'"") AND "
-
strWhere = strWhere & "([goods_status] not Like ""*" & "scrap" & "*"") AND "
Not working at all. Any help is appreciated.
8 2337 ADezii 8,834
Recognized Expert Expert
Can anyone help with filtering records ended with "?".
here is the code I have tried: - strWhere = strWhere & "([stock_site] not like ""*" & "'?'"") AND "
-
strWhere = strWhere & "([goods_status] not Like ""*" & "scrap" & "*"") AND "
Not working at all. Any help is appreciated.
Here is one of several Methods: - strWhere & "Where Not Right(TableName.[stock_site], 1) = '?' AND "
Hi, and Welcome to Bytes!
As you have found, the question mark character is a bit of a problem to use within a Where clause, as it is a wildcard character with a special meaning. There is a means to overcome it, however, using the InStr function, which returns the position of a character within the string if it exists, or 0 if it doesn't.
Your Where clause can be recast as - strWhere = "WHERE Instr([Stock_Site], " & Chr(63) & ") > 0"
(Chr(63) is just the questionmark character referred to by converting its ASCII code.)
This will match if the questionmark occurs anywhere in the string. If you need it to be the end of the string only - and I would caution that this would preclude strings matching if it is anywhere else - you could use - strWhere = "WHERE Instr([Stock_Site], " & Chr(63) & ") = Len([Stock_Site])"
-Stewart
Thank you very much Stewart for your reply.
I will have a try later today.
Kindest regards, Jiwei
Here is one of several Methods: - strWhere & "Where Not Right(TableName.[stock_site], 1) = '?' AND "
It's a magic. Working perfect with my case.
Thank you very much Dezii.
Regards, Jiwei
Here is one of several Methods: - strWhere & "Where Not Right(TableName.[stock_site], 1) = '?' AND "
ADezii 8,834
Recognized Expert Expert
Hi, and Welcome to Bytes!
As you have found, the question mark character is a bit of a problem to use within a Where clause, as it is a wildcard character with a special meaning. There is a means to overcome it, however, using the InStr function, which returns the position of a character within the string if it exists, or 0 if it doesn't.
Your Where clause can be recast as - strWhere = "WHERE Instr([Stock_Site], " & Chr(63) & ") > 0"
(Chr(63) is just the questionmark character referred to by converting its ASCII code.)
This will match if the questionmark occurs anywhere in the string. If you need it to be the end of the string only - and I would caution that this would preclude strings matching if it is anywhere else - you could use - strWhere = "WHERE Instr([Stock_Site], " & Chr(63) & ") = Len([Stock_Site])"
-Stewart
Hello Stewart, I think the OP was specifically looking for values where the '?' appeared at the end of the String. In this case the Instr() Function would not work where there were > 1 '?', the '?' did not appear as the last character, or the '?' appeared in a position other than the last. Kindly correct me if I am wrong.
ADezii 8,834
Recognized Expert Expert
It's a magic. Working perfect with my case.
Thank you very much Dezii.
Regards, Jiwei
We do try to work magic whenever we can! (LOL).
Hi ADezii. The OP did indeed say that the question mark was at the end of the string, in which case using InStr and matching against Len (my second suggestion) would indeed fail if there is more than one questionmark (as InStr would return the position of the first occurrence only). I had pointed out that it would not work if the question mark was anywhere else, and it was implicit in my reply (but not spelt out clearly) that this would include use of more than one question mark.
Personally, I am not keen on use of user-entered marker characters that rely on the user placing the character in a specific position. Users are only human and will make mistakes, and such mistakes should not stop other routines from working.
For example, it is easy to type questionmark-space by mistake at the end of a string - and nearly impossible for the user concerned to spot. Even using RTrim would not guarantee a match, as the user could by mistake type something invalid that did not end in a space, like "?." - there are so many possibilities. A solution matching the last character will always fail in these circumstances, which is why my first suggestion - and it was first because it was the one I preferred - was to match for the questionmark anywhere in the string. This would not be dependent on whether or not there was just one question mark, or where it occurred. The OP has not said whether or not there is just one question mark, and whether or not end of text is the only place it could be, hence the provision of two solutions in my post...
-Stewart
ADezii 8,834
Recognized Expert Expert
Hi ADezii. The OP did indeed say that the question mark was at the end of the string, in which case using InStr and matching against Len (my second suggestion) would indeed fail if there is more than one questionmark (as InStr would return the position of the first occurrence only). I had pointed out that it would not work if the question mark was anywhere else, and it was implicit in my reply (but not spelt out clearly) that this would include use of more than one question mark.
Personally, I am not keen on use of user-entered marker characters that rely on the user placing the character in a specific position. Users are only human and will make mistakes, and such mistakes should not stop other routines from working.
For example, it is easy to type questionmark-space by mistake at the end of a string - and nearly impossible for the user concerned to spot. Even using RTrim would not guarantee a match, as the user could by mistake type something invalid that did not end in a space, like "?." - there are so many possibilities. A solution matching the last character will always fail in these circumstances, which is why my first suggestion - and it was first because it was the one I preferred - was to match for the questionmark anywhere in the string. This would not be dependent on whether or not there was just one question mark, or where it occurred. The OP has not said whether or not there is just one question mark, and whether or not end of text is the only place it could be, hence the provision of two solutions in my post...
-Stewart
Makes perfect sense to me Stewart, thanks for the explanation.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Mark V. |
last post by:
Here's what I have and I'm stumped. I have a table that has several
thousand names and addresses. I only want to send to one address in a
household. So what I would like to do is create a new column that runs
a macro or whatever it takes to flag records so they are housholded.
Some records have a Father and son at the same address, so I would
only want to generate a count in my query that gives me one record for
that household, a head of...
|
by: Jason |
last post by:
I am trying to filter records in a primary form based on records in
related tables. The data in the related tables is being displayed in
the primary form
through subforms. To be more specific, I have a primary form named
TestResults, which is connected to data in a table named TestResults.
There are basically two other tables that are related to the
TestResults table (and the primary form) named Names-Normalized and
SiteAddresses. The...
|
by: William Wisnieski |
last post by:
Hello Everyone,
I have a main form with a datasheet subform that I use to query by form.
After the user selects two criteria on the main form and clicks the
cmdShowResults button on the main form, the subform returns the records
based on the two criteria. The criteria used on the main form are values
selected in two list boxes. When the user clicks on the first list box
(lstCollege), it returns values in the second list box...
|
by: MattB |
last post by:
I have a RadioButtonList then binds to a DataTable in my Web Form. The
DataTextField is called "descrip" and I want to bind only records that don;t
have an empty descrip field.
My initial approach was to loop through the rows collection, test each row's
descrip field and if it's empty delete it. That didn;t work because I guess
you can't delete from a collection you are currently looping on (makes
sense).
I've got some other ideas,...
|
by: |
last post by:
Hello,
Does anyone have an idea on how I can filter the data in the gridview
control that was returned by an sql query?
I have a gridview that works fine when I populate it with data. Now I want
to look at that data and filter it based on what is in it.
I know that this could have been done with data sets and data views in
asp.net 1.1 but how is this done now in asp.net 2.0?
| |
by: LDD |
last post by:
Hi Folks
I'm trying to determine a way to handle paging, filtering and sorting in a
datagrid.
If I choose to filter and sort, I'd like to return a subset. If that
resultset has more records then the number of rows I'd like to display, I'd
like to be able to load pages into the grid.
My question is, do I need to continually hit the db to get the next page of
records, or is there another method of doing with the dataset. i.e. load the
|
by: jvdub22 |
last post by:
I have a vb.net windows form application that has two datagrids on it that have a master - detail relationship. The underlying database is an sql database. The application works fine when I first load the application and query all records. My question is how can I add filtering too my master grid? I would like the user to be able to filter records in the master table and keep the relationship with the detail table. If I use a dataview to do...
|
by: Lyn |
last post by:
I have a problem using the form .Filter and .FilterOn properties which
causes Access to crash (as detailed in a separate post). The form operates
in continuous mode, displaying matching records from a file based on a
search criterion. This basic functionality works just fine.
I decided to allow the user to narrow down the output by providing some
extra controls to allow the user to filter the recordset via the .Filter
form property. ...
|
by: =?Utf-8?B?amV6MTIzNDU2?= |
last post by:
Hi ASP.Net experts
I have a archived SQL Server 2000 database table with about 300,000 records,
and need to display filtered data on a ASP.Net 2 web page.
Basic filtering needs to be done on id, name and DOB fields, however,
advanced filtering could include between 1 and 10 different checkboxes being
check or unchecked.
What would be the best approach to this. Are there any examples I could view?
|
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: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
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...
| |