views:

120

answers:

2

Below SQL query works when the spaces in the role name are replaced by %: 1 row is returned

select * from cmrdata.dbo.tblRoles where rolename like '%Super%Administrator%'

However, when I try to mimic the same in DataView.RowFilter, it does not return any rows.

dv.RowFilter = "RoleName like '[%]" & Replace(roleName, " ", "[%]") & "[%]'"

I also tried without the [] around the %. Please advise.
Thanks for your help in advance.

A: 

Error in Like operator: the string pattern '%super%administrator%' is invalid.

Why are you replacing spaces with a %? What type of rows are you trying to match?

gbogumil
Purpose: I am checking to see if a role with that name already exists. If a role with the same name does not exist, then I insert the new role into the system.I want to ignore spaces when checking if the role name exists
A: 

Kindly suggest using

WHERE role_name like "%SUPER%" 
  AND role_name like "%ADMINISTRATOR%"

or

WHERE role_name like "%SUPER ADMINISTRATOR%"

Don't forget; regular expressions are always there for you if criterion gets to complex.

Cheers.

Mevdiven
for this, I have to break the role name into multiple words. How can I use regular expressions instead?
Use this article; http://stackoverflow.com/questions/194652/sql-server-regular-expressions-in-t-sql
Mevdiven