Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Other Forums
 MS Access
 SQL SELECT with Multiple WHERE Criteria

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2003-09-25 : 08:11:07
ThomasF writes "I have a Access db search looking in multiple fields but I need one static put since the login should restrict the data the user should see. The "client" is a session variable and does restrict the view in other pulls but I have multiple "OR" statements (25 infact) to help search the in important fields.

How do I have the "client" restrict the view while still searching the rest?

Sample:
strSQL = "SELECT * " _
& "FROM tapes " _
& "WHERE client = '%" & Session("Principal") & "%' " _
& "and title LIKE '%" & Replace(strSearch, "'", "''") & "%' " _
& "or title2 LIKE '%" & Replace(strSearch, "'", "''") & "%' " _
& "OR title3 LIKE '%" & Replace(strSearch, "'", "''") & "%' " _
& "OR title4 LIKE '%" & Replace(strSearch, "'", "''") & "%' " _
& "OR title5 LIKE '%" & Replace(strSearch, "'", "''") & "%' " _
& "OR title6 LIKE '%" & Replace(strSearch, "'", "''") & "%' " _
& "OR title7 LIKE '%" & Replace(strSearch, "'", "''") & "%' " _

...etc

your ideas/comments would be most welcome since this is the last hangup on this. I tried subqueries and filters but could never get them to work right.

Thanks in advance."

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2003-09-25 : 08:33:26
Is this Access or SQL ?

Access uses * as the wildcard, not %.

also, you have:

"WHERE client = '%" & Session("Principal") & "%' "


and you are not using the LIKE operator, so you should not have any of the wildcard characters in the right hand side of the = sign.

i.e., should be :


"WHERE client = "'" & Session("Principal") & "' " _




- Jeff
Go to Top of Page

Stoad
Freaky Yak Linguist

1983 Posts

Posted - 2003-09-25 : 08:38:15
Maybe you just forgot to use "(" and ")"???

& "WHERE client = '%" & Session("Principal") & "%' " _
& "and (title LIKE '%" & Replace(strSearch, "'", "''") & "%' " _
& "or title2 LIKE '%" & Replace(strSearch, "'", "''") & "%' " _
& "OR title3 LIKE '%" & Replace(strSearch, "'", "''") & "%' " _
& "OR title4 LIKE '%" & Replace(strSearch, "'", "''") & "%' " _
& "OR title5 LIKE '%" & Replace(strSearch, "'", "''") & "%' " _
& "OR title6 LIKE '%" & Replace(strSearch, "'", "''") & "%' " _
& "OR title7 LIKE '%" & Replace(strSearch, "'", "''") & "%') "
Go to Top of Page
   

- Advertisement -