Click here to Skip to main content
14,836,169 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
Comments
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...

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
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
   
Comments
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...
King Fisher 6-Nov-14 4:05am
   
How?

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