0

我正在使用以下查询:

    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.

请让我知道我哪里错了。

4

1 回答 1

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);';
于 2013-07-31T01:57:40.383 回答