Solved

CREATE LOGIN within Stored Procedure

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

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Question has a verified solution.

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

Suggested Solutions

by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
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…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

919 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

16 Experts available now in Live!

Get 1:1 Help Now