本文介绍了存储过程将计算值分配给变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 限时删除!! 请检查我犯错的存储过程?我试图将计算值分配给变量,我不确定它是否正确。Please check the stored procedure where I did the mistake? I am trying to assign the calculated value to variable and I am not sure is it correct or no.Alter Proc [dbo].[FindAnnualLeave1]@Empid varchar(20)asDeclare @AnnualPending intSelect @AnnualPending =(select (0.0821917808219178) *DATEDIFF(d, e.doj,GETDATE())- l.Leaves where l.EmpLeaveCode='Annual') From EmployeeLeaves linner join EmployeeMaster e on l.EmpID=e.EmpIDwhere l.EmpID=e.EmpIDreturn @AnnualPendingGo 没有回复此查询,我想在命令按钮点击后将此变量显示给asp.net lable。谢谢nothing returns this query , I want to show this variable to asp.net lable once the command button clicks. thanks推荐答案如果你试图从SQL的其他部分获取值,你必须像这样运行这个SP:If you try to get the value from other parts of the SQL you have to run this SP like this:DECLARE @RV AS INTEXEC @RV = FindAnnualLeave1(1)SELECT @RV 从代码中你应该使用ExecuteScalar方法:http://msdn.microsoft.com/en-us/library/37hwc7kt.aspx [ ^ ] --- 另一种选择是 SELECT @AnnualPending 而不是 RETURN @AnnualPending ,但它是mos tly取决于你的设计...From code you should use the ExecuteScalar method: http://msdn.microsoft.com/en-us/library/37hwc7kt.aspx[^]---An other option is to do SELECT @AnnualPending instead of RETURN @AnnualPending, but it mostly depends on your design...Alter Proc [dbo].[FindAnnualLeave1]@Empid varchar(20)asDeclare @AnnualPending intSelect @AnnualPending =(select (0.0821917808219178) *DATEDIFF(d, e.doj,GETDATE())- l.Leaves where l.EmpLeaveCode='Annual') From EmployeeLeaves linner join EmployeeMaster e on l.EmpID=e.EmpIDwhere l.EmpID=e.EmpIDselect @AnnualPendingGo 这篇关于存储过程将计算值分配给变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 1403页,肝出来的.. 09-08 10:38