Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASP Equivalent of 'SQL IN' operator

Status
Not open for further replies.

Haybails90

Programmer
Sep 3, 2004
57
US
I'm looking for an ASP (VBScript) equivalent to the SQL IN operator. I have an IF statement and I need to check if the value I'm considering is equal to any value in a lengthy group of values. Plus, this group of values is dynamic. So I just want to throw this group and my number and see if my number matches any of the values in the group.




Haybails90
 
You might want to try InStr()...

Code:
dim sINList,sSearchVAR
sINList = "VALUE1|VALUE2|VALUE3|VALUE4"
sSearchVAR = "VALUE3"

if instr(1, sINList,sSearchVAR) > 0 then
  'present, do something
else
  'not present, do something else
end if

InStr returns the position of the seacrh value in the search string you pass it, if it is not found 0 is returned.

Depending on what type of data you will be comparing, you may want to change the delimiter so that no conflicts occur when searching.

i.e.:
Searching for "ab,2" from a comma separated list will probably yield incorrect results.

You would need to convert your values to strings though.

A smile is worth a thousand kind words. So smile, it's easy! :)
 
I would additionally suggest including delimiters at the beginnning and end of both the delimited string and the search string. This way you want get partial results: ie, search for day in a list that includes tuesday.
Code:
Dim list, val
list = "#Apple#Tuesday#Blah#Something#"
val = "Day"

If InStr(list,val) > 0 Then
   'found it in list
Else
   'didn't find it
End If

-T

barcode_1.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top