来自链接服务器的SSMS调用标量函数

时间:2018-12-18 10:31:37

标签: sql sql-server ssms microsoft-dynamics

我想从链接服务器[SQLCRM]中调用标量函数

select 
   o.EstimatedValue [EstimatedSum],
   (select * from OPENQUERY([SQLCRM], 'convert(date, [DBNAME].dbo.fn_UTCToTzSpecificLocalTime(o.tisa_registrationdate, 
                       us.TimeZoneBias,
                       us.TimeZoneDaylightBias,
                       us.TimeZoneDaylightYear,
                       us.TimeZoneDaylightMonth,
                       us.TimeZoneDaylightDay,
                       us.TimeZoneDaylightHour,
                       us.TimeZoneDaylightMinute,
                       us.TimeZoneDaylightSecond,
                       0,
                       us.TimeZoneDaylightDayOfWeek,
                       us.TimeZoneStandardBias,
                       us.TimeZoneStandardYear,
                       us.TimeZoneStandardMonth,
                       us.TimeZoneStandardDay,
                       us.TimeZoneStandardHour,
                       us.TimeZoneStandardMinute,
                       us.TimeZoneStandardSecond,
                       0,
                       us.TimeZoneStandardDayOfWeek),103)')) as DateKey

   from [SQLCRM].[DBNAME].dbo.Opportunity o left join
            [SQLCRM].[DBNAME].dbo.tisa_Article a on o.OpportunityId  = a.tisa_OpportunitySalesId left join
            [SQLCRM].[DBNAME].dbo.SystemUserBase u on u.SystemUserId = 'DB159B57-4A3D-E311-93EC-00155D46BF05' left join
            [SQLCRM].[DBNAME].dbo.UserSettingsBase us on us.SystemUserId = u.SystemUserId

运行此查询后,出现以下错误:

链接服务器“ SQLCRM”的OLE DB提供程序“ SQLNCLI11”返回消息“无法完成延迟的准备。”。

调用该函数的正确格式是哪种?谢谢

1 个答案:

答案 0 :(得分:0)

sp_configure 'Show Advanced Options', 1
GO
RECONFIGURE
GO
sp_configure 'Ad Hoc Distributed Queries', 1
GO
RECONFIGURE
GO
OPENROWSET('SQLNCLI', 
'Server=ipHere\ExtentionNameifHas;Database=DBName;Uid=userName;PWD=Password;'
,'SET FMTONLY OFF;SET NOCOUNT ON;Paste the query over here'