问题:@CountAppNo int out 这个变量为什么不能输出数据,格式那边出问题了,语句中间应该没问题
- SQL code
CREATE PROCEDURE P_AppointPercent_test2@S_BeginTime datetime , --开始时间 是由查询的医生提供@S_EndTime datetime , --结束时间@DeptID NVarChar(50), --部门编号@AllDept bit, --查询所有部门@CountApp int out, --预约人数@CountAppYse int out, --赴约人数@CountAppNo int out --赴约人数ASset @sql=N' select @CountApp=count(*) '+ N' from AppointList a ' + N' left join ' + @TableName +' b 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,[email protected]_BeginTime datetime,@S_EndTime datetime,@CountApp int output',@S_BeginTime,@S_EndTime,@CountApp output
因为同样的格式,不过我不是写在存储过程里边,下边就能出结果。 我上边的格式错在什么地方?
- SQL code
declare @TableName nvarchar(100),@Sql nvarchar(1000)declare @S_BeginTime datetime,@S_EndTime datetimedeclare @CountApp int --outputset @TableName = 'YY_TEST.dbo.gh_ghzdk b'select @S_BeginTime='2012-04-18',@S_EndTime='2012-04-19' 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,[email protected]_BeginTime datetime,@S_EndTime datetime,@CountApp int output',@S_BeginTime,@S_EndTime,@CountApp outputselect @CountApp
------解决方案--------------------
[email protected]?
------解决方案--------------------
- SQL code
你的这 @CountAppYse int out, --赴约人数@CountAppNo int out --赴约人数两 没有接收赋值的过程也的放到 exec sp_executesql @sql,[email protected]_BeginTime datetime,@S_EndTime datetime,@CountApp int output',@S_BeginTime,@S_EndTime,@CountApp output这个里做相应的声明 和接收过程