Click here to Skip to main content
15,891,184 members

how to return value from procedure

heta.dave asked:

Open original thread
I have following store procedure..
I want to return values of variables p,na,sh,fh,na
plz help me what shoulb be done..
SQL
ALTER PROCEDURE [dbo].[sp_attendence]
	@empid nvarchar(100),
	@year int,
	@month int
AS
BEGIN
	
	SET NOCOUNT ON;
	

	declare @anoon bit;
	declare @bnoon bit;
	declare @absent bit;
	declare @attendence int;
	
	declare @fh int;
	declare @a int;
	declare @sh int;
	declare @p int;
	declare @i int
	declare @na int
	declare @noofdays int;
	
	set @i=1;
	set @fh=0
	set @sh=0
	set @a=0;
	set @p=0;
	set @na=0;
	
	SELECT @noofdays=dbo.udf_GetNumDaysInMonth(@month,@year);

	while(@i<=@noofdays)
	begin
	select @anoon =anoon,@bnoon=bnoon,@absent=absent from dbo.sms_hr_EmpAttendence where empid=@empid and year=@year and month=@month and day=@i
	
	if(@anoon ='1' and @bnoon='1')
	begin
		set @p=@p+1;
	end
	
	else if(@bnoon ='1' and @anoon='0')
		begin
			SET @fh=@fh+1
		end
		
	ELSE if(@bnoon='0' and @anoon='1')
	begin
		set @sh=@sh+1
	end
	
	else if(@bnoon='0' and @anoon ='0')
	begin
		set @a=@a+1
	end
	
	else
	begin
	set @na=@na+1;
	end
	 
	
	set @i=@i+1;
	end

    
END
Tags: SQL Server

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



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