|
Posted by Brian Sprogψ on 01/22/08 08:46
Hi Dan,
I modified the script to look like this, and it worked like a charm :-)
USE [master]
GO
DECLARE @brugernavn as char(50)
DECLARE @password as char(50)
DECLARE @SqlStatement nvarchar(MAX);
set @brugernavn = 'testbruger'
set @password = N'testpassword'
SET @SqlStatement =
N'CREATE LOGIN ' +
QUOTENAME(@brugernavn) +
N' WITH PASSWORD = ' +
QUOTENAME(@password, '''') +
N', DEFAULT_DATABASE=[master], DEFAULT_LANGUAGE=[us_english],
CHECK_EXPIRATION=ON, CHECK_POLICY=ON ';
EXECUTE (@SqlStatement);
use [testbase]
SET @SqlStatement =
N'CREATE USER ' +
QUOTENAME(@brugernavn) +
N' FOR LOGIN ' +
QUOTENAME(@brugernavn)
EXECUTE (@SqlStatement);
GO
Thanks a lot for your help.
Best regards,
Brian
Dan Guzman skrev:
>> How do I get the script to do what I want it to ?
>
> Not all DCL commands accept variables (see BOL syntax) so you'll need to
> use dynamic SQL. For example:
>
> DECLARE @SqlStatement nvarchar(MAX);
>
> SET @SqlStatement =
> N'CREATE LOGIN ' +
> QUOTENAME(@brugernavn) +
> N' WITH PASSWORD = ' +
> QUOTENAME(@password, '''');
>
> EXECUTE (@SqlStatement);
>
Navigation:
[Reply to this message]
|