视图或自定义函数调用存储过程结果集办法(可执行动态SQL)

CREATE   PROC  p_test
as
SELECT   GETDATE () a

go


CREATE   VIEW  v_test
AS  
SELECT   *   FROM   OPENROWSET ( ' SQLOLEDB.1 ' , ' server=FI6/SQL2008;uid=sa;pwd=123 ' , ' exec test11.dbo.p_test ' )

go

SELECT   *   FROM  V_TEST
/*
a
2009-09-01 11:08:30.197
*/

CREATE   FUNCTION  FN_TEST()
RETURNS   TABLE  
AS  
RETURN (
    
SELECT   *   FROM   OPENROWSET ( ' SQLOLEDB.1 ' , ' server=FI6/SQL2008;uid=sa;pwd=123 ' , ' exec test11.dbo.p_test ' )
)
go

SELECT   *   FROM  FN_TEST()
/*
a
2009-09-01 11:08:30.197
*/

你可能感兴趣的:(数据库)