USE YourDB
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_WARNINGS OFF
GO
PRINT 'Date: ' + CONVERT(VARCHAR(24),GETDATE(),13) + ' Server Name: '
+ @@servername + ' Service Name: ' + @@servicename;
GO
IF EXISTS
(SELECT *
FROM sys.objects
WHERE name = 'Describe_Remote_UDF_Attributes')
drop procedure reporting.Describe_Remote_UDF_Attributes;
PRINT 'drop procedure reporting.Describe_Remote_UDF_Attributes';
GO
PRINT 'CREATE PROCEDURE reporting.Describe_Remote_UDF_Attributes';
GO
CREATE PROC reporting.Describe_Remote_UDF_Attributes
/*****************************************************************************
Description: This procedure describes attributes of user defined function
which resides on remote server using Link Service and stores it to ##temp table.
Change Log
# Date Who Change
*****************************************************************************/
@runUDF NVARCHAR(MAX)
,@LinkServiceName NVARCHAR(256)
AS
BEGIN
SET NOCOUNT ON;
DECLARE @strExe NVARCHAR(MAX) = 'sp_describe_first_result_set @tsql = N'''
,@strExecAt NVARCHAR(MAX);
IF OBJECT_ID('tempdb..##temp') IS NOT NULL DROP TABLE ##temp;
CREATE TABLE ##temp (
is_hidden sql_variant
,column_ordinal sql_variant
,name sql_variant
,is_nullable sql_variant
,system_type_id sql_variant
,system_type_name sql_variant
,max_length sql_variant
,[precision] sql_variant
,scale sql_variant
,collation_name sql_variant
,user_type_id sql_variant
,user_type_database sql_variant
,user_type_schema sql_variant
,user_type_name sql_variant
,assembly_qualified_type_name sql_variant
,xml_collection_id sql_variant
,xml_collection_database sql_variant
,xml_collection_schema sql_variant
,xml_collection_name sql_variant
,is_xml_document sql_variant
,is_case_sensitive sql_variant
,is_fixed_length_clr_type sql_variant
,source_server sql_variant
,source_database sql_variant
,source_schema sql_variant
,source_table sql_variant
,source_column sql_variant
,is_identity_column sql_variant
,is_part_of_unique_key sql_variant
,is_updateable sql_variant
,is_computed_column sql_variant
,is_sparse_column_set sql_variant
,ordinal_in_order_by_list sql_variant
,order_by_is_descending sql_variant
,order_by_list_length sql_variant
,tds_type_id sql_variant
,tds_length sql_variant
,tds_collation_id sql_variant
,tds_collation_sort_id sql_variant
);
SET @strExe = @strExe + '''SELECT * FROM ' + @runUDF + '''';
SET @strExecAt = 'INSERT INTO ##temp EXEC (''' + @strExe + ''''') AT '
+ @LinkServiceName;
EXEC(@strExecAt);
END;
/***********************************************
Test Sample:
EXEC reporting.Describe_Remote_UDF_Attributes
'YourSchema.dbo.YourUDF(
default
,default
,default
,default
,default
)'
,'LinkServiceName';
SELECT * FROM ##temp;
*************************************************/
GO
If you find this script useful please donate generously.
No comments:
Post a Comment