SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GOALTER PROCEDURE testproc
@datebegin datetime,
@dateend datetime
ASdeclare @sql nvarchar(4000)set @sql = 'select * from rdrecord where ddate between ''' + @datebegin + ''' and ''' + @dateend + ''''exec(@sql)GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
为什么调用exec testproc @datetime = '2010-1-1', @dateend = '2010-1-31'总是出错:从字符串转换为 datetime 时发生语法错误。
@datebegin varchar(30),
@dateend varchar(30)
ASdeclare @sql nvarchar(4000)set @sql = 'select * from rdrecord where ddate between ''' + @datebegin + ''' and ''' + @dateend + ''''exec(@sql)GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
exec('select * from rdrecord where ddate between ''' + @datebegin + ''' and ''' + @dateend + '''')