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

Using 'Like' with 'If' statement ??

Hi,

Quick question.

If I have a recordset value in RS("ProductName"), is it possible to
test for a part string in this value ?

I would be looking for all products starting 'Blue' and with misc
endings.
So I will require the search string Blue.*

Can I do something like:
If RS("ProductName") = like(Blue.*) then.....

or

can this only be done within the select statement ?
Thanks
David
Jul 19 '05 #1
2 14746
"David" wrote ...
If I have a recordset value in RS("ProductName"), is it possible to
test for a part string in this value ?
yes
can this only be done within the select statement ?


If you want to do this within the ASP and not the select statement, you can
use InStr.

InStr will return a numeric value for the character location of the first
found match.

So -

strText = "blue.pants"

Location = InStr(strText, "blue")

In this case, InStr would return as 1 - the first character in the string
etc...

You would need to put this in the loop for your recordset.

Do While Not RS.BOF And Not RS.EOF

strText = RS("text")

Location = InStr(strText, "blue")

If InStr > 0 Then
' do something
End If

RS.MoveNext
Loop
You might also want to put LCase() around strText within the InStr line
above - then you can be sure it wont be case sensitive etc when matching...

To be honest, depending on your needs, it might be a lot quicker to just
change your SQL statement to return all the records you want where it
already contains "blue" in the relevant field etc...

Hope this helps,

Regards

Rob
Jul 19 '05 #2
David wrote:
Hi,

Quick question.

If I have a recordset value in RS("ProductName"), is it possible to
test for a part string in this value ?

I would be looking for all products starting 'Blue' and with misc
endings.
So I will require the search string Blue.*

Can I do something like:
If RS("ProductName") = like(Blue.*) then.....

or

can this only be done within the select statement ?
Thanks
David


In addition to Robb's suggestion (InStr), you can use the recordset's Filter
property and the recordset's Find method to perform a Like comparison. Check
them out in online help (go to msdn.microsoft.com/library if you have no
online help installed on your pc. The ADO reference is in the Data Access
node)

However, you would be much better off incorporating this filter in the SQL
statement so that you will not be retrieving unneeded records across the
network. Be conservative of your network's resources. In addition, you can
perform more powerful comparisons in SQL than you can in either Filter or
Find.

HTH,
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 19 '05 #3

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

Similar topics

28
by: Daniel | last post by:
Hello =) I have an object which contains a method that should execute every x ms. I can use setInterval inside the object construct like this - self.setInterval('ObjectName.methodName()',...
4
by: Japhy | last post by:
Hello, I'm am pulling data from a mysql db and want to use the data to populate a <ul. Here are relavent parts of my code : $wohdate = mysql_result($wohRS,$wohndx,woh_date); $woh_display...
121
by: typingcat | last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so on. I've tried many PHP IDEs today, but almost non of them supported Unicode (UTF-8) file. I've found that the only Unicode...
4
by: banz | last post by:
Hello I have a problem to resolve: I wrote a Perlscript which caches data from a server (local on my machine) I would like to have a other connection to a remote server but I don't know how to...
8
by: Andrew Robinson | last post by:
Are these two equivalent? Is one better than the other? I tend to go with #1 but started wondering.... Thanks, 1: using (SqlConnection cn = new SqlConnection(DataConnection)) using...
7
by: Serge Rielau | last post by:
Hi all, Following Ian's passionate postings on problems with ALTOBJ and the alter table wizard in the control center I'll try to explain how to use ALTOBJ with this thread. I'm not going to get...
8
by: rbg | last post by:
I did use query plans to find out more. ( Please see the thread BELOW) I have a question on this, if someone can help me with that it will be great. In my SQL query that selects data from table,...
3
by: Clearview | last post by:
This is my first post to the forum and hoping I can get help as I have spent a way too much time on this problem, and thinking it is probably something really simple to resolve. I am using Access...
6
markmcgookin
by: markmcgookin | last post by:
Hi Folks, I am running a simple query using VB (This isnt a VB Question, dont worry!) on SQL Server Compact. I have the query below being created, and then added to if a flower location doesn't...
13
by: jkimbler | last post by:
As part of our QA of hardware and firmware for the company I work for, we need to automate some testing of devices and firmware. Since not everybody here knows C#, I'm looking to create a new...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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.