表名改变量后出现错误
不知道该怎么改
declare @TableName nvarchar(100),@Sql nvarchar(1000)set @TableName = 'YY_TEST.dbo.gh_ghzdk b' set @sql=N'select @CountApp=count(*) '+ N'from AppointList a' + N'left join ' + @TableName +' on a.MedicalNo=b.blh and dbo.f_IsSameDate(a.AppointTime,b.ghrq)=1' + N'where AppointTime >= @S_BeginTime and AppointTime<= @S_EndTime and b.blh is null and a.cancel=0' exec sp_executesql @sql,N'@S_BeginTime datetime,@S_EndTime datetime,@CountApp int output',@S_BeginTime,@S_EndTime,@CountApp output下边注释掉的是可以正常运行的 /* select @CountAppNo=count(*) --爽约人数,算出爽约率就行了,在对赴约进行重复记录Distinc是,可能去掉预约多科室的情况。 from AppointList a left join YY_TEST.dbo.gh_ghzdk b on a.MedicalNo=b.blh and dbo.f_IsSameDate(a.AppointTime,b.ghrq)=1 where AppointTime >= @S_BeginTime and AppointTime<= @S_EndTime and b.blh is null and a.cancel=0 */