Monday, March 11, 2013

Multiple Query in Single Query

Here we go:

select sum(isnull(rejectedcount,0)) as RejectedCount,AssignedtoCW from smotaskmaster where AssignedtoCW is not null  group by AssignedtoCW;

select count(*) as Approved, AssignedtoCW from smotaskmaster where (approvedbysmo=1 and approvedbyseo=1) and AssignedtoCW is not null group by AssignedtoCW;

select count(*) as Worked, AssignedtoCW from smotaskmaster where AssignedtoCW is not null and lengthcontentdesccw is not null group by AssignedtoCW;

select count(*) as pending, AssignedtoCW from smotaskmaster where (approvedbysmo=0 or approvedbyseo=0) and AssignedtoCW is not null group by AssignedtoCW;


I have tried so many thing but it doesn't work in the last finally it works for me :-


Select AssignedtoCW,sum(isnull(rejectedcount,0)) as RejectedCount,
Approved=(select count(*) from smotaskmaster  where (approvedbysmo=1 and approvedbyseo=1) AND SMM.AssignedtoCW =AssignedtoCW),
Worked=(select count(*) from smotaskmaster where AssignedtoCW=SMM.AssignedtoCW  and lengthcontentdesccw is not null),
Pending=(select count(*) as pending from smotaskmaster where (approvedbysmo=0 or approvedbyseo=0) AND SMM.AssignedtoCW =AssignedtoCW )
From smotaskmaster SMM  WHERE
SMM.AssignedtoCW is not null group by AssignedtoCW


above  query is given for your help you can modify your queries like this..... 



No comments:

Post a Comment