访问 table 由 SP 的 table 值函数返回

Accessing table returning by table-valued function from SP

我有 table 值函数

ALTER FUNCTION [dbo].[fn_Functiont]()
RETURNS TABLE 
AS
RETURN 
(   
SELECT d.*, b.Name AS Name, ps.Name AS PaymentSystemName, c.UserName AS UserName, c.FirstName AS ClientFirstName, c.LastName AS LastName, c.Number AS DocumentNumber, c.Id
FROM Document AS d
JOIN System AS ps ON d.SystemId = ps.Id
JOIN Client AS c ON c.Id = d.ClientId
LEFT JOIN Shop AS b ON b.Id = d.ShopId
WHERE d.OperationTypeId IN (2, 4, 5) AND c.Type = 1
)

还有SP。在那个 SP 中,我已经像这样

声明了临时 table
DECLARE @tempTable AS TABLE 
(
   .. columns here ...
)

声明后我只是插入信息

INSERT INTO @tempTable
SELECT * FROM [dbo].[fn_Functiont]()
Select @column1,colum2...,from @tempTable

问题是我必须在@temptable 中声明很多列,代码看起来像 ugly.So 是否有更好的方法从 table 读取 SP 中的行值函数?

而不是 table 变量 @tempTable 使用温度 Table 并试试这个

SELECT * INTO #tempTable FROM [dbo].[fn_Functiont]()