"Sagaert Johan" wrote in message
> Hi
> If i remove the square brackets i get a syntax error
>
> My sp is declared as :
>
> ALTER PROCEDURE dbo.AddAdminUser
> (
> @newuser nvarchar(256),
> @newpw varchar
> )
> AS
> CREATE USER @newuser FOR LOGIN @newuser;
> RETURN
The syntax error is caused because CREATE USER cannot take a variable as an
argument.
You can work around this by executing the proc using dynamic SQL:
CREATE PROCEDURE dbo.AddAdminUser (
@newuser nvarchar(256),
@newpw varchar
)
AS
DECLARE @sql varchar(max)
SET @sql = ('CREATE USER ' + @newuser + ' FOR LOGIN ' + @newuser)
EXEC @sql
RETURN
--
Lawrence Garvin, M.S., MCITP(x2), MCTS(x5), MCP(x7), MCBMSP
Principal/CTO, Onsite Technology Solutions, Houston, Texas
>> Stay informed about: problem with stored proc