?
Solved

CREATE LOGIN within Stored Procedure

Posted on 2007-11-21
3
Medium Priority
?
787 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 500 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

Does Your Cloud Backup Use Blockchain Technology?

Blockchain technology has already revolutionized finance thanks to Bitcoin. Now it's disrupting other areas, including the realm of data protection. Learn how blockchain is now being used to authenticate backup files and keep them safe from hackers.

Question has a verified solution.

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

Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

719 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