当我尝试执行此 sql 语句时出现错误。将字符串转换为 smalldatetime 数据类型时转换失败。
有谁知道我做错了什么?
declare @modality varchar(50)
declare @datefrom smalldatetime
set @modality = 'xxxxxxx'
set @datefrom = '20090101'
declare @var1 nvarchar(4000)
select @var1 =
'select
sum('+ @modality +') as ' + dbo.fnc_titlecase(@modality) +'
from dbo.vw_RawData
where vw.date >= ' + @datefrom + ''
exec sp_executesql @var1