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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can I use an * in an IN statement in SQL? 1

Status
Not open for further replies.

juschuma

Programmer
Oct 23, 2002
18
US
I have a multiselect listbox with the following values:

*
Pacific
Texas
Northeast
Southeast

Those are divisions. I'm running a query which brings back values based on what is selected in the listbox. In my VBA code, I cycle through the selected listbox rows and build an IN statement. Example: if Pacific and Texas are selected:

Select field from table where Division in ('Pacific', 'Texas').

This works fine. SQL returns correct values. However, if the user selects the *, I want the query to return all values. The SQL then becomes:

Select field from table where Division in ('*'). That obviously doesn't work. Is there someway I can use a LIKE statement combined with the IN statement.

The other way (which I'd prefer not to do) is to code the listbox to highlight all the rows whenever the * row is selected.

Any suggestions
 
You need to Control in Code, Like
If Me!
  • <> '*' then
    strWhere = Where Clause
    end if

    strsql = &quot;Select * from table1&quot; & strWhere

    Hope this helps Please remember to give helpful posts the stars they deserve!
    This makes the post more visible to others in need!
 
Thank you. I just did an IF statement.

If (first row is selected) Then
query with LIKE *
Else
build query with IN statement
End If
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top