vendredi 17 juillet 2015

Cursor which create user and assign role

I have list of users which all will requer to be on server which used domain autentification, I have temp table in which Ian loading my users from cab file. Than I need to create users based on records in my temp file

How to do cursor to create this records?

I was trying to do

Declare @userprofile varchar(20)

Declare cursor1 cursor for Select * from #temp; Open cursor1 Fetch next from cursor1 Into @userprofile while @@fetch_status =0 Begin Create user @userprofile for login @userprofile Go Exec sp_addrolemember 'role' , @userprofile Fetch next from cursor1 Into @userprofile End Close cursor1 Deallocate cursor1 However it's throwing me an error Msg 102 Incorrect syntax near @userprofile and msg 137 must declare the scalar variable @userprofile Sorry for formatting can do it only from phone :(

Please any help?

Aucun commentaire:

Enregistrer un commentaire