Solved

CREATE LOGIN within Stored Procedure

Posted on 2007-11-21
3
786 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 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

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

626 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