Solved

CREATE LOGIN within Stored Procedure

Posted on 2007-11-21
3
777 Views
Last Modified: 2013-11-06
I need to create a login in a stored procedure.
CREATE LOGIN [MYDOMAIN\TestPerson] FROM WINDOWS;

Above works fine. However, I need to pass the login name into the spoc. The code below does not work.

DECLARE @Log varchar(50)
SET @Log = '[MYDOMAIN\TestPerson]'
CREATE LOGIN @Log FROM WINDOWS;

How can I do this?

Thanks
Bob
0
Comment
Question by:rcl58
  • 2
3 Comments
 
LVL 16

Expert Comment

by:SQL_SERVER_DBA
ID: 20327723
Try this instead...

DECLARE
  @Log Varchar(50),
  @sql varchar(500)

set @sql = 'CREATE LOGIN '+ @Log
exec (@sql)
0
 
LVL 16

Accepted Solution

by:
SQL_SERVER_DBA earned 125 total points
ID: 20327732
sorry...

DECLARE
  @Log Varchar(50),
  @sql varchar(500)
SET @Log = '[MYDOMAIN\TestPerson]'
set @sql = 'CREATE LOGIN '+ @Log
exec (@sql)
0
 

Author Closing Comment

by:rcl58
ID: 31410363
Thanks
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now