473,666 Members | 2,237 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Filtering records with question mark at the end

17 New Member
Can anyone help with filtering records ended with "?".

here is the code I have tried:

Expand|Select|Wrap|Line Numbers
  1.  strWhere = strWhere & "([stock_site] not like ""*" & "'?'"") AND "
  2.  strWhere = strWhere & "([goods_status] not Like ""*" & "scrap" & "*"") AND "
Not working at all. Any help is appreciated.
Oct 27 '08 #1
8 2337
ADezii
8,834 Recognized Expert Expert
Can anyone help with filtering records ended with "?".

here is the code I have tried:

Expand|Select|Wrap|Line Numbers
  1.  strWhere = strWhere & "([stock_site] not like ""*" & "'?'"") AND "
  2.  strWhere = strWhere & "([goods_status] not Like ""*" & "scrap" & "*"") AND "
Not working at all. Any help is appreciated.
Here is one of several Methods:
Expand|Select|Wrap|Line Numbers
  1. strWhere & "Where Not Right(TableName.[stock_site], 1) = '?' AND "
Oct 27 '08 #2
Stewart Ross
2,545 Recognized Expert Moderator Specialist
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

Expand|Select|Wrap|Line Numbers
  1. 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

Expand|Select|Wrap|Line Numbers
  1. strWhere = "WHERE Instr([Stock_Site], " & Chr(63) & ") = Len([Stock_Site])"
-Stewart
Oct 27 '08 #3
Jiwei06xie
17 New Member
Thank you very much Stewart for your reply.

I will have a try later today.

Kindest regards, Jiwei

Here is one of several Methods:
Expand|Select|Wrap|Line Numbers
  1. strWhere & "Where Not Right(TableName.[stock_site], 1) = '?' AND "
Oct 27 '08 #4
Jiwei06xie
17 New Member
It's a magic. Working perfect with my case.

Thank you very much Dezii.

Regards, Jiwei

Here is one of several Methods:
Expand|Select|Wrap|Line Numbers
  1. strWhere & "Where Not Right(TableName.[stock_site], 1) = '?' AND "
Oct 27 '08 #5
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

Expand|Select|Wrap|Line Numbers
  1. 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

Expand|Select|Wrap|Line Numbers
  1. 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.
Oct 27 '08 #6
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).
Oct 27 '08 #7
Stewart Ross
2,545 Recognized Expert Moderator Specialist
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
Oct 27 '08 #8
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.
Oct 27 '08 #9

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

Similar topics

3
4679
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...
3
11097
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...
19
3534
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...
3
1427
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,...
7
14802
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?
5
1905
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
2
1745
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...
0
1999
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. ...
2
1300
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?
0
8440
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, 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...
0
8355
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,...
0
8781
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 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...
0
7381
agi2029
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...
1
6191
isladogs
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...
0
5662
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();...
1
2769
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
2
2006
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1769
bsmnconsultancy
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...

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.