dynamicrevolutions
asked on
SQL Statement checking for restricted username
I've a problem here which is, IF let say when somebody signup with the username of 'adminForever'
How do i restrict him from using the "ADMIN" in his username or others name that listed in my table "tblrestrictedname"???
How do i compare it?
declare @username as nvarchar(50)
set username='adminForever'
if not exists(select * from tblmember where username like @username) ???
How do i restrict him from using the "ADMIN" in his username or others name that listed in my table "tblrestrictedname"???
How do i compare it?
declare @username as nvarchar(50)
set username='adminForever'
if not exists(select * from tblmember where username like @username) ???
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
set @username='adminForever'
IF NOT EXISTS(SELECT 1 FROM tblRestrictedName WHERE @username LIKE '%' + Name + '%')
BEGIN
-- Allow username to be used
END
This will check whether any restricted names appear *anywhere* in the username.
So, if "admin" was listed in tblRestrictedName, it would rule out "adminForever", "Foreveradmin", "Hadmint" etc etc