15,999,626 members
See more:
hi All

Here i have problem with this query i want total number of columns,
My Query:

SQL
`select distinct rd.UserID,sm.EmpNameC,(select count(UserId) from RawData where TimeEntry between '06/Nov/2014 09:00:00 AM' and '06/Nov/2014 10:00:00 AM') as 'BreakFast' from RawData as rd inner join  StaffMaster as sm on rd.UserID=sm.UserIdN`

Output Like:

BreakFast
0
0
0
0
like this i want total sum of this column, what to do....
Posted
Thanks7872 6-Nov-14 2:09am
Total number of columns? Are you sure? Its not clear to me what you are going to do. Would you please explain it?
prasanna.raj 6-Nov-14 2:19am
i need sum of total columns... how to make the query for that...

## Solution 1

C#
```select distinct count(UserId)
from RawData
where TimeEntry between '06/Nov/2014 09:00:00 AM'
and '06/Nov/2014 10:00:00 AM') as 'BreakFast'
from RawData as rd
inner join  StaffMaster as sm
on rd.UserID=sm.UserIdN```

v2

## Solution 2

try this:
SQL
```select *from ( select distinct rd.UserID,sm.EmpNameC from RawData as rd inner join  StaffMaster as sm on rd.UserID=sm.UserIdN) t1 inner join
(select count(UserId),userId from RawData where TimeEntry between '06/Nov/2014 09:00:00 AM' and '06/Nov/2014 10:00:00 AM' group by userId) t2 on t1.userId=t2.userId```

The Syntax is :

SQL
`select *from (select userId,name from table1)t1 inner join (select count(userid),name from table2)t2 on t1.userId=t2.userId`

prasanna.raj 6-Nov-14 2:26am
In this i have error like 'No column was specified for column 1 of 't2'.
'
King Fisher 6-Nov-14 2:36am
make count(userid) as count
prasanna.raj 6-Nov-14 2:26am
how to sum total breakfast columns.
King Fisher 6-Nov-14 2:37am
We can't see your table Data's ,better you could Show your table structure with Some sample Data's
prasanna.raj 6-Nov-14 3:47am
Thanks i got it...