Click here to Skip to main content
15,893,487 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
The following query

SQL
select T1.*,
case when T1.Status='0'
then 'open'
else csm.[SName]
end   as SName from
(select count([Status]) as cnt,[Status] from CRMaster where date = convert(datetime,@Date,103)
 group by [Status]) as T1
left join [StatMaster] as csm on csm.[StaCode]= T1.[Status]



SQL
results in

2   0   open
2   ab  close
1   bc  pend



i want total no of records as 5 (2+2+1).How can i get this value? I need to display tot no. of rows in my form.
Posted
Updated 29-May-14 3:20am
v2
Comments
CHill60 29-May-14 9:24am    
Select COUNT(*) FROM CRMaster ??

Assuming you want the invidual totals and the grand total, add the following:

SQL
union
select count([Status]) as cnt, 'Total', '' from CRMaster where date = convert(datetime,@Date,103)


The union and extra select should match the number of columns from the first select and provide the grand total; if you want the grand total at the bottom, add an order by.
 
Share this answer
 
Comments
CHill60 29-May-14 9:31am    
5'd
Hello ,
try this
SQL
select sum(x.cnt) from
(
select T1.cnt,
case when T1.Status='0'
then 'open'
else csm.[SName]
end   as SName from
(select count([Status]) as cnt,[Status] from CRMaster where date = convert(datetime,@Date,103)
 group by [Status]) as T1
left join [StatMaster] as csm on csm.[StaCode]= T1.[Status]
) x


thanks
 
Share this answer
 
Comments
pwavell 29-May-14 9:32am    
this query just gives me 5.Actuly i want cnt in one seperate column along with other columns as given above.
Animesh Datta 30-May-14 1:41am    
you may follow this link
http://www.codeproject.com/Tips/334400/Concatenate-many-rows-into-a-single-text-string-us


this will help you to concatenate many rows in a single row.

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