tags:

views:

34

answers:

2

The below is my query,its getting a formation error,the query will describe the structure of it .....Could anyone help for this

SELECT (CAST(Empid AS VARCHAR)+' '+EmployeeName) AS Employee
       ,COUNT(ActualDate)Total_No_Days 
       ,(SELECT COUNT(ActualDate)
            from BufferListforBilling 
            where BufferEmpName IS NOT NULL 
            GROUP BY EmpId) as BillDays
       ,(SELECT COUNT(ActualDate)
            from BufferListforBilling 
            where BufferEmpName IS NULL 
            GROUP BY EmpId) as NonBillDays
FROM BufferListforBilling 
WHERE Team = 'ABC'
GROUP BY Empid ,EmployeeName


Empid   ActualDate    EmpName   BuffEmpNames
===========================================
1       5/6/10        Roy       NULL
1       6/6/10        Roy       NULL
1       7/6/10        Roy       Assigned
1       8/6/10        Roy       Assigned
2       5/6/10        Deb       Assigned
2       6/6/10        Deb       NULL
2       7/6/10        Deb       NULL
2       8/6/10        Deb       NULL

The above is my table structure and i need to get a ouput like Below

Employee  Total_No_of_Days   Bill_Days  Non_Bill_Days
===============================================================
1-Roy     4                  2          2
2-Deb     4                  1          3
A: 

It looks like you are concatenating strings with +. As far as i know, SQL does not support this. You should take a look at the CONCAT()-function.

elusive
that is working fine only ,my need is to get the other two vlaues of that inner query in ()
Prabhakaran
@elusive, some versions of SQL (eg. SQLServer) do support `+` as a string concatenation operator.
Mark Bannister
@Mark Bannister: All right, thanks for the information.
elusive
+3  A: 

You use subqueries in the select part, which is allowed only if they return scalar (single column and single row) value.

It seems that

SELECT COUNT(ActualDate)
from BufferListforBilling 
where BufferEmpName IS NOT NULL 
GROUP BY EmpId) as BillDay

Returns more than one row (due to group by).

It is not completely clear what your intention is. If you explain exactly what is that you want you will get better help. Also, do state your RDBMS engine.

EDIT Taking a (hopefully not so) wild guess try this

SELECT (CAST(Empid AS VARCHAR)+' '+EmployeeName) AS Employee
       ,COUNT(ActualDate) Total_No_Days 
       ,COUNT(BufferEmpName) as BillDays
       ,COUNT(BufferEmpName)-COUNT(ActualDate) as NonBillDays
FROM BufferListforBilling 
WHERE Team = 'ABC'
GROUP BY Empid ,EmployeeName

(do notice that your Total_No_Days will count only rows where AcutalDate is NOT NULL; use COUNT(*) if you want to count all rows)

Unreason
Empid ActualDate EmpName BuffEmpNames =========================================== 1 5/6/10 Roy NULL 1 6/6/10 Roy NULL 1 7/6/10 Roy Assigned 1 8/6/10 Roy Assigned 2 5/6/10 Deb Assigned 2 6/6/10 Deb NULL 2 7/6/10 Deb NULL 2 8/6/10 Deb NULL The above is my table structure and i need to get a ouput like Below Employee Total_No_of_Days Bill_Days Non_Bill_Days =============================================================== 1-Roy 4 2 2 2-Deb 4 1 3
Prabhakaran
Did you try my suggested query? I think it will give you what you need
Unreason