Click here to Skip to main content
15,885,896 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
Alter Procedure dashbord --1--@userid=1
@userid int
AS
Begin

declare @reportmanager int
declare @admintype int
-- normal employee admintype = 0 , managers admintype > 0
set @reportmanager = (select managerid from reportingperson where employeeid=@userid)
set @admintype = (select  admintype from employee where content_id=@userid)


--select a.content_id ,a.imagetype,b.Fromdate,b.Todate,b.leaveapp,b.leavesubject,b.Reason,b.status,b.createddate from Employee a join leaves b on a.content_id=b.employeeid where a.content_id=@userid
if exists (select 1 where @reportmanager > 0 and @admintype=0)
begin
select b.contentid,x.content_id,x.employeename,x.imagetype,
convert(varchar(10),b.Fromdate,126) as fromdate,convert(varchar(10),b.Todate,126) as Todate,b.leaveapp,b.leavesubject,
b.Reason,(case when (b.status=0) then 'Pending' else 'Approved' end) AS status,convert(varchar(10),b.createddate,126) as Createddate from

  leaves b
left outer join employee x on b.employeeid=x.content_id
where (b.employeeid=@userid --or b.employeeid in (select managerid from reportingperson where employeeid=@userid)
) and b.status=0

select admintype from employee
 where content_id = @userid
 end
 else
 begin
 select b.contentid,x.content_id,x.employeename,x.imagetype,
convert(varchar(10),b.Fromdate,126) as fromdate,convert(varchar(10),b.Todate,126) as Todate,b.leaveapp,b.leavesubject,
b.Reason,(case when (b.status=0) then 'Pending' else 'Approved' end) AS status,convert(varchar(10),b.createddate,126) as Createddate from

  leaves b
left outer join employee x on b.employeeid=x.content_id
where  b.employeeid in (select employeeid from reportingperson where managerid=@userid)  and b.status=0

select admintype from employee
 where content_id = @userid

 end
  End




how to solve this
i have done single reporting person
then how to do for multiple reporting person
Posted

You have to check your select statements because one of all returns more than one value, you can start with this:

SQL
set @admintype = (select admintype from employee where content_id=@userid)
 
Share this answer
 
v2
One of these;
SQL
set @reportmanager = (select managerid from reportingperson where employeeid=@userid)
set @admintype = (select  admintype from employee where content_id=@userid)
are returning more than one value and you cannot assign a list of ints to a single int.

Since you're only using those for the first if-statement you might be able to change them to
SQL
set @reportmanager = (select count(managerid) from reportingperson where employeeid=@userid)
set @admintype = (select max(admintype) from employee where content_id=@userid)

as I am guessing you're only making sure that they're there or not there.

Having said that, without seeing your actual table structure and knowing what you're trying to select it's difficult to help.


/Fredrik
 
Share this answer
 
Comments
[no name] 17-Sep-13 10:05am    
this will work right

set @reportmanager = (select count(managerid) from reportingperson where employeeid=@userid)
set @admintype = (select max(admintype) from employee where content_id=@userid)
Fredrik Bornander 17-Sep-13 10:14am    
Did it work for you?
Or are you asking me if it will work?
[no name] 17-Sep-13 10:19am    
thanks

I have to now once the person have approved the leave the notification has to go to the another reporting person
[no name] 17-Sep-13 10:20am    
then approve the leave and employee can go to this house
Fredrik Bornander 17-Sep-13 10:22am    
Yeah, I'm sorry to say I'm not following you at all now.

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