Alter Login on Stored procedure

  • Hi, I need to implement a stored procedure to create a new login and to change password for logins (Sql Server Ent Edition 2005 sp2).

    I'm using this sintax only to test how to pas values to create login and alter login sentence

    DECLARE @ULOGIN sysname

    SET @ULOGIN = 'TESTER'

    ALTER LOGIN @ULOGIN WITH PASSWORD = '222222222' OLD_PASSWORD = '11111111';

    But alter login sentence is not getting @ulogin value and i need to pass password and old password.

    How can I do this.

    I need some advice, thanks for any help.

  • You need to use dynamic sql in order to do this

    DECLARE @ULOGIN sysname

    DECLARE @sql nvarchar(500)

    SET @ULOGIN = 'TESTER'

    SET @sql = 'ALTER LOGIN ' + @ULOGIN + ' WITH PASSWORD = ''222222222'' OLD_PASSWORD = ''11111111''';

    EXEC sp_executesql @sql

    [font="Verdana"]Markus Bohse[/font]

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply