SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Save row counts of multiple query results


Save row counts of multiple query results

Author
Message
solig.fi
solig.fi
Grasshopper
Grasshopper (20 reputation)Grasshopper (20 reputation)Grasshopper (20 reputation)Grasshopper (20 reputation)Grasshopper (20 reputation)Grasshopper (20 reputation)Grasshopper (20 reputation)Grasshopper (20 reputation)

Group: General Forum Members
Points: 20 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!
Samuel Vella
Samuel Vella
Hall of Fame
Hall of Fame (4K reputation)Hall of Fame (4K reputation)Hall of Fame (4K reputation)Hall of Fame (4K reputation)Hall of Fame (4K reputation)Hall of Fame (4K reputation)Hall of Fame (4K reputation)Hall of Fame (4K reputation)

Group: General Forum Members
Points: 3967 Visits: 2144
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
solig.fi
solig.fi
Grasshopper
Grasshopper (20 reputation)Grasshopper (20 reputation)Grasshopper (20 reputation)Grasshopper (20 reputation)Grasshopper (20 reputation)Grasshopper (20 reputation)Grasshopper (20 reputation)Grasshopper (20 reputation)

Group: General Forum Members
Points: 20 Visits: 35
thanks a lot! that works great like i want it to do! :-D
LutzM
LutzM
SSC-Forever
SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)

Group: General Forum Members
Points: 47939 Visits: 13559
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
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum







































































































































































SQLServerCentral


Search