Solved

CREATE LOGIN within Stored Procedure

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

INTRODUCTION: While tying your database objects into builds and your enterprise source control system takes a third-party product (like Visual Studio Database Edition or Red-Gate's SQL Source Control), you can achieve some protection using a sing…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
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.

770 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