触发每天运行的动态SQL Server存储过程

时间:2014-12-12 14:13:18

标签: sql-server function stored-procedures sap

我有一个在SSMS中运行的动态存储过程。是否有可能将此proc转换为函数,以便我什么时候

exec function stored.proc

我可以从我的ETL运行吗?

我的查询如下 -

create procedure dbo.bear_load
 as
 set nocount on;

 Declare @cols as NVARCHAR(MAX), @query as NVARCHAR(MAX), @Result as NVARCHAR(MAX)

select @cols = STUFF((SELECT ',' + QUOTENAME(FIELD_NAME) 
                from bear_crossjoin
                group by Field_Name, FIELDNUMBER
                order by FIELDNUMBER
        FOR XML PATH(''), TYPE
        ).value('.', 'NVARCHAR(MAX)') 
    ,1,1,'')

set @query = N'SELECT ' + @cols + N'  
            from 
            (
                select substring, Field_Name,
                  rn = row_number() over(partition by field_name order by fieldnumber)
                from bear_crossjoin
            ) x
            pivot 
            (
                max(substring)
                for Field_Name in (' + @cols + N')
            ) p ' 
set @Result= ' select ' + @query 
EXEC (@query)
GO


exec dbo.bear_load

非常感谢任何帮助。

阿伦

0 个答案:

没有答案