Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 6th, 2008, 03:17 PM
Authorized User
 
Join Date: Mar 2007
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default Is there a "like" option?

In SQL you can do

Code:
where LAST_NAME like 'JOH%'
Is it possible to do something similar in ASP in an IF?

Code:
If LAST_NAME like "JOH%" Then
Thanks!

 
Old June 6th, 2008, 03:57 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

It all depends on what exactly you are going for. If you are looking for the exsistance of a given group of characters in a string such as you have shown, you can use the InStr() function.

Consider:

Dim string1, pos

string1 = "Jonathan"
pos = InStr(string1, "Jon")
Response.Write pos '1 would be wrote to the screen

hth.
-Doug

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7
================================================== =========
 
Old June 6th, 2008, 04:05 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Code:
Sure... The INSTR() function!!!

WHERE field LIKE '%xyz%' ==>>
      IF InStr( 1, field, "xyz", vbTextCompare ) > 0 Then 

WHERE field LIKE 'xyz%' ==>>
      IF InStr( 1, field, "xyz", vbTextCompare ) = 1 Then 

WHERE field LIKE '%xyz' ==>>
      IF InStr( 1, field, "xyz", vbTextCompare ) = Len(field)-Len("xyz")+1 Then 

The vbTextCompare emulates SQL by making the search non-case-sensitive.
Use vbBinaryCompare (or just omit the parameter) if you want a case-sensitive compare.

As alternatives to the latter two searches, you could do:

WHERE field LIKE 'xyz%' ==>>
      IF StrComp( Left(field,LEN("xyz")), "xyz", vbTextCompare ) = 0 Then 

WHERE field LIKE '%xyz' ==>>
      IF StrComp( Right(field,LEN("xyz")), "xyz", vbTextCompare ) = 0 Then 

You decide which you prefer.
http://msdn.microsoft.com/en-us/library/wybb344c(VS.85).aspx
 
Old June 6th, 2008, 04:07 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

A comment on DPARSONS' answer:

Don't forget that INSTR( ) used with only two parameters is case sensitive. So it doesn't really match SQL's "LIKE" operator in that form. The alternative form I show allows you your choice of case sensitivity or not.
 
Old June 9th, 2008, 03:42 PM
Authorized User
 
Join Date: Mar 2007
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Folks!!






Similar Threads
Thread Thread Starter Forum Replies Last Post
Option for decode yogeshyl SQL Language 0 July 6th, 2008 11:52 PM
Create Check Boxes/Option buttons/Option Group hewstone999 Access VBA 1 March 14th, 2008 07:25 AM
if option kgoldvas XSLT 1 May 14th, 2007 09:39 AM
Option group vnadig Access 6 September 8th, 2004 02:53 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.