Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Save row counts of multiple query results Expand / Collapse
Author
Message
Posted Tuesday, August 03, 2010 12:55 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, November 10, 2010 11:01 PM
Points: 4, Visits: 35
Hi,

I have quite many queries and i would like to save its row count results into a single table, also by adding some kind of identifier to the row count results.

this is what i have for now, which works not how i would like to output the results;

select count(*) as 'FI' from
(
select
land1
from kna1
where land1 = 'FI'
) count_FI

UNION

select count(*) as 'SE' from
(
select
land1
from kna1
where land1 = 'SE'
) count_SE

The result from the above query is :

FI (Column name)
100 (this is result of the 2nd query, but its difficult to know, as it takes into account the lowest no. of rows)
123 (result of the 1st query, for FI)

i would like to have it outputed in a certain format if its even possible.

Result_Description Row_Count Result_Date
SE_Country 100 03/08/2010
FI_Country 123 03/08/2010

also these results to be saved in another table, along with a date, i guess that could just be automated when the record was created?

Thanks!
Post #962621
Posted Tuesday, August 03, 2010 3:46 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: 2 days ago @ 8:46 AM
Points: 335, Visits: 1,956
I think what you're looking for is:

select 'SE_Country' as col1, count(*) from .....
union all
select 'FE_Country' as col1, count(*) from ....
union all

Post #962674
Posted Tuesday, August 03, 2010 4:05 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, November 10, 2010 11:01 PM
Points: 4, Visits: 35
thanks a lot! that works great like i want it to do!
Post #962684
Posted Tuesday, August 03, 2010 5:31 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Tuesday, April 01, 2014 9:38 AM
Points: 6,908, Visits: 12,624
Wouldn't it be easier to do it in one query? Or am I missing the obvious?

SELECT land1, COUNT(*)
FROM kna1
WHERE land1 IN('SE', 'FI')
GROUP BY land1





Lutz
A pessimist is an optimist with experience.

How to get fast answers to your question
How to post performance related questions
Links for Tally Table , Cross Tabs and Dynamic Cross Tabs , Delimited Split Function
Post #962719
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse