我使用以下查询:
IF OBJECT_ID('dbo.StudentDestination') IS NULL
begin
Select *,getdate() MyTimeStamp
into AkshayDestination..StudentDestination
From AkshaySource..sys.dm_io_virtual_file_stats(NULL, NULL)
End
Else
Begin
Insert into AkshayDestination..StudentDestination
select *,getdate() MyTimeStamp
From AkshaySource..sys.dm_io_virtual_file_stats(NULL, NULL)
End
这基本上是一种将表中的所有数据复制到其他表的方法(添加了一个时间戳列以确定插入时间)
但它给了我一个错误:
Msg 4122, Level 16, State 1, Line 6
Remote table-valued function calls are not allowed.
请告诉我错误的地方。
答案 0 :(得分:2)
错误消息对我来说似乎很明显。一种可能的解决方法是在远程服务器上创建存储过程:
CREATE PROCEDURE dbo.whatever
AS
BEGIN
SET NOCOUNT ON;
SELECT *,getdate() MyTimeStamp
From sys.dm_io_virtual_file_stats(NULL, NULL);
END
GO
然后在本地服务器上:
Insert into AkshayDestination..StudentDestination
EXEC AkshaySource.databasename.dbo.whatever;
另一个想法是使用动态SQL:
Insert into AkshayDestination..StudentDestination
EXEC AkshaySource...sp_executesql N'SELECT *, GETDATE()
FROM sys.dm_io_virtual_file_stats(NULL, NULL);';