这个存储过程哪里错了

sidney 2008-07-11 11:58:00
CREATE procedure sp_YG_StUnitMedPlan
@unitID char(36),
@plansum float output
as
--定义游标
declare cur cursor for select sum(RetirePlanSum+OntheJobPlanSum) from HRW_YG_UnitMedicalPlan join ORG_Unit ON HRW_YG_UnitMedicalPlan.UnitID=ORG_Unit.ID
where ID=''+@unitID+''
--定义一个变量来接收游标的值
--打开游标
open cur
set @plansum=0.0--给@plansum初值
--提取游标的值
fetch next from cur into @plansum
if @@fetch_status<>0
print '错误'
print @plansum
--关闭游标
close cur
--销毁游标
deallocate cur
GO

我在查询分析器中这样调用:
declare @f float
exec sp_YG_StUnitMedPlan '7AE0A3FB-2D6C-4E51-8B10-71EAFA2D2690',f

出现错误为:
服务器: 消息 8114,级别 16,状态 4,过程 sp_YG_StUnitMedPlan,行 0
将数据类型 nvarchar 转换为 float 时出错。
...全文
84 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhiguo2008 2008-07-11
  • 打赏
  • 举报
回复
select cast(sum(RetirePlanSum+OntheJobPlanSum) as float) from HRW_YG_UnitMedicalPlan join ORG_Unit ON HRW_YG_UnitMedicalPlan.UnitID=ORG_Unit.ID
where ID=''+@unitID+''
wgzaaa 2008-07-11
  • 打赏
  • 举报
回复
调用时f前少了@
中国风 2008-07-11
  • 打赏
  • 举报
回复
GUID時不用加''引號
ID=@unitID
中国风 2008-07-11
  • 打赏
  • 举报
回复
declare @f float
exec sp_YG_StUnitMedPlan '7AE0A3FB-2D6C-4E51-8B10-71EAFA2D2690',@f output
--這樣用
sidney 2008-07-11
  • 打赏
  • 举报
回复
知道了,用@f,谢谢了
中国风 2008-07-11
  • 打赏
  • 举报
回复
exec sp_YG_StUnitMedPlan '7AE0A3FB-2D6C-4E51-8B10-71EAFA2D2690',f
,f--傳參改改
中国风 2008-07-11
  • 打赏
  • 举报
回复
CREATE procedure sp_YG_StUnitMedPlan
@unitID char(36),
@plansum float output
as
--定义游标
declare cur cursor for
select sum(RetirePlanSum+OntheJobPlanSum)
from HRW_YG_UnitMedicalPlan join ORG_Unit ON HRW_YG_UnitMedicalPlan.UnitID=ORG_Unit.ID
where ID=@unitID----------------------這里改改
--定义一个变量来接收游标的值
--打开游标
open cur
set @plansum=0.0--给@plansum初值
--提取游标的值
fetch next from cur into @plansum
if @@fetch_status <>0
print '错误'
print @plansum
--关闭游标
close cur
--销毁游标
deallocate cur
GO
sidney 2008-07-11
  • 打赏
  • 举报
回复
sum(RetirePlanSum+OntheJobPlanSum)是flaot型

34,837

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧