您可以在表值函數的視圖做到這一點。這看起來是這樣的:
-- === Table-Valued function ====================================
--
create function fn_foo (
@Date datetime
) returns @ResultSet table (
DateKey datetime
,DisplayDate varchar (20)
) as
insert @ResultSet (
DateKey
,DisplayDate
)
select DateKey -- Just pretend there's something to select
,DisplayDate -- behind the scenes
from ods.Dates
where DateKey <= @Date
return
go
-- === View ============================================
--
create view vw_foo (
DateKey
,DisplayDate
) as
select DateKey
,DisplayDate
from fn_foo ('2009-04-31')
go
有幾個注意事項:
查看同類問題:http://stackoverflow.com/questions/728898/can-you-do-a-select-on-the-results-of-a-stored-procedure-in-t- SQL – 2009-04-28 08:11:07
http://stackoverflow.com/questions/916784/how-to-call-stored-procedure-in-a-view – 2012-09-20 16:11:16