Click here to Skip to main content
15,896,557 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
alter PROCEDURE Sp_GetDetailsLeaves_PaySlip
(
@empid varchar(15),
@fromdate date,
@todate date
)
AS
BEGIN

Declare @tot int
Declare @pd int
Declare @Lt int
Declare @Ab int

set @tot =(SELECT SUM(othrs) as totothrs FROM Tbl_Daily_Attendence where emp_id = @empid and cdate between @fromdate and @todate )

set @Lt =( SELECT COUNT(cdate) as Leavestaken FROM Tbl_Daily_Attendence where emp_id='@empid' and cdate between '@fromdate' and '@todate' and attendencetype ='L')

set @Ab =( SELECT COUNT(cdate) as Leavestaken FROM Tbl_Daily_Attendence where emp_id='@empid' and cdate between '@fromdate' and '@todate' and attendencetype ='A')

Declare @sql varchar(250)
select @sql = (select distinct @tot as Othrs,@pd as Presentdays ,@Lt as Leavetaken,@Ab as Absents from Tbl_Daily_Attendence)

Exec(@sql)

print @sql
END
Posted
Comments
Maciej Los 25-Feb-14 7:37am    
Not a question!

You SQL builds (by using SET) are not OK, you should setup your SQL by using string concatenations then finally invoke "EXECUTE sp_executesql".
You can see an example in my next article (the SP "GetContactsByFilterPaginated" ): Advanced ASPX GridView Pagination and Data Entities[^]
 
Share this answer
 
just remove single quotes to all the scalar parameters.
 
Share this answer
 

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