Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.

SQL
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



nothing returns this query , I want to show this variable to asp.net lable once the command button clicks. thanks
Posted
Updated 9-Nov-14 3:15am
v2
Comments
Kornfeld Eliyahu Peter 9-Nov-14 9:10am    
How do you try to check the return value?
tastini 9-Nov-14 9:14am    
I call this procedure from asp , and tried only select statement from sql
Maciej Los 9-Nov-14 16:29pm    
Not clear!

1 solution

If you try to get the value from other parts of the SQL you have to run this SP like this:
SQL
DECLARE @RV AS INT
EXEC @RV = FindAnnualLeave1(1)
SELECT @RV

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...
SQL
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
 
Share this answer
 
v2
Comments
tastini 9-Nov-14 9:23am    
I am sorry to ask you , what I have to change in my query? its the same query am running except one that you mention (return to select) I tried that before but I got no column message. please edit it for me. just want to learn too.
Kornfeld Eliyahu Peter 9-Nov-14 9:25am    
See update...
tastini 9-Nov-14 9:27am    
i am getting null value using that query.
Kornfeld Eliyahu Peter 9-Nov-14 9:29am    
Check the value of your select without the SP...
tastini 9-Nov-14 9:36am    
No Column Name "NULL"

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900