SQL Statement checking for restricted username

Posted on 2005-04-14
Medium Priority
Last Modified: 2006-11-18
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) ???
Question by:dynamicrevolutions
LVL 28

Accepted Solution

rafrancisco earned 2000 total points
ID: 13782796
Try this one:

declare @username as nvarchar(50)
set @username='adminForever'

IF EXISTS (SELECT * FROM tblRestrictedName
WHERE UserName LIKE '%' + @username + '%' OR
           @UserName LIKE '%' + UserName + '%')
--- Not Allowed
LVL 23

Expert Comment

ID: 13782827
declare @username as nvarchar(50)
set @username='adminForever'

IF NOT EXISTS(SELECT 1 FROM tblRestrictedName WHERE @username LIKE '%' + Name + '%')
        -- Allow username to be used

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

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
I have a large data set and a SSIS package. How can I load this file in multi threading?
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how the fundamental information of how to create a table.
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question