Thursday, October 14, 2010

How to get users and primary email address from server database

just execute the below query

DECLARE @DB_Name varchar(100)
DECLARE @Command nvarchar(200)
DECLARE database_cursor CURSOR FOR
SELECT name
FROM master.sys.sysdatabases

OPEN database_cursor

FETCH NEXT FROM database_cursor INTO @DB_Name

WHILE @@FETCH_STATUS = 0
BEGIN
SELECT @Command = 'SELECT SF.fullname, SF.internalemailaddress FROM '+@DB_NAME+'.dbo.systemuserbase SF'
IF @DB_NAME like '%_MSCRM'
EXEC sp_executesql @Command

FETCH NEXT FROM database_cursor INTO @DB_Name
END

CLOSE database_cursor
DEALLOCATE database_cursor


Sudhanshu

No comments:

Post a Comment