SQL-Server 2005: Login name as variable?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Hello,

this follow code run successfull:

ALTER PROCEDURE [dbo].[test_user]
AS
DECLARE @sql nvarchar(150)
BEGIN
CREATE LOGIN [HM\WHubert] FROM WINDOWS WITH DEFAULT_DATABASE=[TEST],
DEFAULT_LANGUAGE=[Deutsch];
END

I will the code flexible. The login name even as variable. See you
next code:

SET @sql = 'HM\WHubert';
CREATE LOGIN [@sql] FROM WINDOWS WITH DEFAULT_DATABASE=[TEST],
DEFAULT_LANGUAGE=[Deutsch];

This Code generate the follow error message:

'@sql' ist kein gültiger Windows NT-Name. Geben Sie den vollständigen
Namen im folgenden Format an: <domain>\<username>.


A other variante with exec:

SET @sql = 'CREATE LOGIN [HM\WHubert] FROM WINDOWS WITH
DEFAULT_DATABASE=[TEST], DEFAULT_LANGUAGE=[Deutsch]'
EXEC @sql

This Code generate the follow error message:

Der Name 'CREATE LOGIN [HM\WHubert] FROM WINDOWS WITH
DEFAULT_DATABASE=[TEST], DEFAULT_LANGUAGE=[Deutsch]' ist kein gültiger
Bezeichner.


The login name is possible most flexible?

My environment: SQL2005 version: 9.00.3161.00

Cu

Wolfram Hubert
.



Relevant Pages

  • Re: Permission question - another one
    ... If I add an Sql Login it does add the TRAVAC\ in front of the names, ... seems to be users that were setup to use SQL Server Authentication. ... RAPTOR is the Server that has SQL Server running on it. ... > " I could think I am taking permissions away from someone, ...
    (microsoft.public.sqlserver.programming)
  • Re: SQL 2k5 SP2 Mirroring - SQL in Mixed mode.
    ... US\sqlservices (old SQLservice account) still member of built-in local admin ... Login: US\sqlservices ... How can I transfer the SQL logins to ... Here is SP_help_revlogin results from the Principal Server (NYSQL-3) ...
    (microsoft.public.sqlserver.clustering)
  • Re: Renamed Windows login not found in SQL Server 2000
    ... It's almost like SQL tuck some knowledge away in an area ... of memory that only gets released on Windows stop. ... > I am running SQL Server 2000 SP2 with Windows ... > login gets corrupted) I am unable to add the new login to ...
    (microsoft.public.sqlserver.security)
  • Re: SQL Server on XP Home Network
    ... The sa account is the system administrator "God" account witihin SQL ... This account is a SQL-Server login. ... You might be able to use Enterprise Manager to go in and create a new SQL ... Select the "SQL Server Authentication" ...
    (microsoft.public.sqlserver.setup)
  • Re: Changing DB Owner
    ... specified login must not already be a user in the database. ... USE MyDatabase ... EXEC sp_changedbowner 'SQLAdmin' ... SQL Server MVP ...
    (microsoft.public.sqlserver.server)