存储过程将计算值分配给变量 [英] Stored Procedure assign the calculated value to variable

查看:80
本文介绍了存储过程将计算值分配给变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请检查我犯错的存储过程?我试图将计算值分配给变量,我不确定它是否正确。



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)
as
Declare @AnnualPending int

Select @AnnualPending =(select (0.0821917808219178) *
DATEDIFF(d, e.doj,GETDATE())- l.Leaves where l.EmpLeaveCode='Annual')

 From EmployeeLeaves l
inner join EmployeeMaster e on l.EmpID=e.EmpID
where l.EmpID=e.EmpID
return @AnnualPending
Go

< br $>




没有回复此查询,我想在命令按钮点击后将此变量显示给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 INT
EXEC @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)
as
Declare @AnnualPending int

Select @AnnualPending =(select (0.0821917808219178) *
DATEDIFF(d, e.doj,GETDATE())- l.Leaves where l.EmpLeaveCode='Annual')

 From EmployeeLeaves l
inner join EmployeeMaster e on l.EmpID=e.EmpID
where l.EmpID=e.EmpID
select @AnnualPending
Go


这篇关于存储过程将计算值分配给变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆