IF OBJECT_ID('tempdb..#clr')IS NOT NULL BEGIN;
	DROP TABLE #clr;
END;

CREATE TABLE #clr ( [PublicKey] varbinary(8000), [name] nvarchar(128), [permission_set_desc] nvarchar(60), [modify_date] datetime, [create_date] DATETIME, dbName VARCHAR(100) )

DECLARE @q NVARCHAR(MAX);
DECLARE @tpl NVARCHAR(MAX) = '
USE @db@

INSERT INTO #clr([PublicKey], [name], [permission_set_desc], [modify_date], [create_date],[dbName])
SELECT 
    CAST(ISNULL(ASSEMBLYPROPERTY(a.name, N''PublicKey''), CONVERT(varbinary(8000), N'''')) AS varbinary(8000)) AS [PublicKey]
    ,[a].[name]
    ,[a].[permission_set_desc]
    ,[a].[modify_date]
    ,[a].[create_date]
    ,''@db@''
FROM sys.[assemblies] [a]
WHERE [a].[is_user_defined] = 1

';

/* declare variables */
DECLARE @name NVARCHAR(100)

DECLARE csr_assemblies CURSOR FAST_FORWARD READ_ONLY FOR 
    SELECT [d].[name] 
    FROM sys.[databases] [d]

OPEN csr_assemblies

FETCH NEXT FROM csr_assemblies INTO @name

WHILE @@FETCH_STATUS = 0
BEGIN
    SELECT @q = REPLACE(@tpl,'@db@', @name);
    EXEC (@q);

    FETCH NEXT FROM csr_assemblies INTO @name
END

CLOSE csr_assemblies
DEALLOCATE csr_assemblies

SELECT * 
FROM [#clr] [c]

