Stored procedures 将DateTime参数发送到链接的服务器存储过程

Stored procedures 将DateTime参数发送到链接的服务器存储过程,stored-procedures,linked-server,sql-server-2017,Stored Procedures,Linked Server,Sql Server 2017,我需要在链接服务器上调用一个存储过程,该服务器具有DateTime参数 我目前正在使用以下查询 SET @RunSP = 'EXEC [Database].[dbo].[sp_MySP] @StartDate = convert(datetime, '''+@S+''') , @EndDate = convert(datetime, '''+@E+ ''') '; 我尝试了不同的方法来转换我的DateTime参数,但每次 我得到以下错误: Msg 241, Level 16, State 1,

我需要在链接服务器上调用一个存储过程,该服务器具有
DateTime
参数

我目前正在使用以下查询

SET @RunSP = 'EXEC [Database].[dbo].[sp_MySP] @StartDate = convert(datetime, '''+@S+''') , @EndDate = convert(datetime, '''+@E+ ''') ';
我尝试了不同的方法来转换我的
DateTime
参数,但每次 我得到以下错误:

Msg 241, Level 16, State 1, Line 14
Conversion failed when converting date and/or time from character string.

@S
@E
转换为字符串格式
YYYYMMDD
,并用单引号括起来

SET @RunSP  = 'EXEC [Database].[dbo].[sp_MySP] @StartDate = ''' + convert(varchar(10), @S, 112) + ''', @EndDate = '''  + convert(varchar(10), @E, 112) + ''''
提示:执行
print@RunSP
以查看输出

Example @RunSP Output :
EXEC [Database].[dbo].[sp_MySP] @StartDate = '20170101', @EndDate = '20170101'

@S
@E
的数据类型是什么?@Squirrel-DateTime<代码>声明@S日期时间声明@E日期时间集@S=N'2017/01/01';设置@E=N'2017/01/01'