Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 How to get Rowcount along with table data

Author  Topic 

dhani
Posting Yak Master

132 Posts

Posted - 2009-07-24 : 18:29:07
Hello All,

is there any trick to solve this? seems to be something exist but unable to catchup...., please kindly help me....


i have one empt table in DB, it has pleantly of records, number ofrecords changes everyday(addnew , or delete some.. etc)
how to display the no of rows as the bottom of the value

for example i have emp table with below data

EmpID, Ename, Sal, City, HasDL
------------------------------
101,Kirk,2000,NYC,Y
102,Clarie,4000,BOSTON,Y
103,Sinit,6000,CHICAGO,Y
104,Sommu,7000,ARPII,N
105,Bomu,9000,DUMMU,N

how can i show as below (format doesn't matter for the count)


EmpID, Ename, Sal, City, HasDL
------------------------------
101,Kirk,2000,NYC,Y
102,Clarie,4000,BOSTON,Y
103,Sinit,6000,CHICAGO,Y
104,Sommu,7000,ARPII,N
105,Bomu,9000,DUMMU,N
Count,5 items

please Help me

Thanks in advance
dhani

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-07-25 : 03:12:21
Where do you want to show the data?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

ayamas
Aged Yak Warrior

552 Posts

Posted - 2009-07-25 : 08:38:07
Maybe this

select col1,col2,col3 from yourtable
union
select '','Count',(select count(*)from yourtable)
Go to Top of Page

dhani
Posting Yak Master

132 Posts

Posted - 2009-07-26 : 16:18:38
Thanks for your response Madhivanan

i want to show after the table rows


please....


Go to Top of Page

dhani
Posting Yak Master

132 Posts

Posted - 2009-07-26 : 16:20:30
Hi ayamas,

Thanks for your response, is it is possible as a single query altogether because i am using some tool which takes only from part of sql query so it is fits as a single query (i mean single from clause)

please....

Thanks for your previous answer,

Best Regards
dhani
Go to Top of Page

ayamas
Aged Yak Warrior

552 Posts

Posted - 2009-07-27 : 00:40:48
quote:
Originally posted by dhani

Hi ayamas,

Thanks for your response, is it is possible as a single query altogether because i am using some tool which takes only from part of sql query so it is fits as a single query (i mean single from clause)

please....

Thanks for your previous answer,

Best Regards
dhani



Maybe used a derived query

select * from
(
select col1,col2,col3 from yourtable
union
select '','Count',(select count(*)from yourtable)
)t

or use a temp table & insert the resultset of the union query in the temp table.
Go to Top of Page

dhani
Posting Yak Master

132 Posts

Posted - 2009-07-27 : 13:33:08
Hi Ayamas,

Thanks for your answer,

i execute below query the result is fine but it seems to be that i need to pass some date in union query, in the count row i would like to show just count word (in first column) and count value in last column is it possible? (i tried by giving just passing empty string it didn't work, ofcourse because different data types but if i pass a date then it displays tha date which is a little bit awkwarding.... any idea please)


select * from
(
select id,date,value from t1
union all
select '','2/2/2008',(select count(*)from t1) as zeco
)t



----------------------


and also you suggested in previous post use temp table & insert the result can you breif it if it is possible please

Thanks in advance ayamas,

Best Regards
dhani
Go to Top of Page

ayamas
Aged Yak Warrior

552 Posts

Posted - 2009-07-28 : 02:41:29
Please post some sample data & the expected output.It will let me or anyone else understand your requirements better.
Please have a look at this on how to post your sample data.

http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspx
Go to Top of Page
   

- Advertisement -