Unix Technical Forum

sql

This is a discussion on sql within the SQL Server forums, part of the Microsoft SQL Server category; --> I am having trouble linking four count statements. Each statment is a count for a different table. The statements ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-29-2008, 03:53 AM
johnjayp
 
Posts: n/a
Default sql

I am having trouble linking four count statements. Each statment is a
count for a different table. The statements can be seen below;

select count (*) from xwrsct01
select count (*) from xwrmvt01
select count (*) from xtrdlt01
select count (*) from xtrvrt01

I need the statement to return seperate values for each table.

Any help would be appreciated.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-29-2008, 03:53 AM
Hugo Kornelis
 
Posts: n/a
Default Re: sql

On 10 Aug 2004 04:24:35 -0700, johnjayp wrote:

>I am having trouble linking four count statements. Each statment is a
>count for a different table. The statements can be seen below;
>
>select count (*) from xwrsct01
>select count (*) from xwrmvt01
>select count (*) from xtrdlt01
>select count (*) from xtrvrt01
>
>I need the statement to return seperate values for each table.
>
>Any help would be appreciated.


Hi johnjayp,

You could use either

SELECT 'xwrsct01' AS TabName, COUNT(*) AS NumRows
FROM xwrsct01
UNION ALL
SELECT 'xwrmvt01' AS TabName, COUNT(*) AS NumRows
FROM xwrmvt01
....

to get 4 rows with table name and count.

Or you could use

SELECT (SELECT COUNT(*) FROM xwrsct01) AS xwrsct01,
(SELECT COUNT(*) FROM xwrmvt01) AS xwrmvt01,
....

to get all counts on one row.

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-29-2008, 03:53 AM
Emmanuel Petit
 
Posts: n/a
Default Re: sql

2 differents ways to do it:
1/ select count(xwrsct01.name of one column of the table xwrsct01) as
xwrsct01Count, count(xwrmvt01.name of one column of the table xwrmvt01) as
xwrmvt01Count, count (xtrdlt01.name of one of collum of the table xtrdlt01)
as xtrdlt01Count, count (xtrvrt01.name of one column of the table xtrvrt01)
as xtrvrt01Count from xwrsct01 , xwrmvt01, xtrdlt01, xtrvrt01

the result will show as :
xwrsct01Count xwrmvt01Count xtrdlt01Count xtrvrt01Count
20 45 32
41

2/ select count (*) from xwrsct01
union
select count (*) from xwrmvt01
union
select count (*) from xtrdlt01
union
select count (*) from xtrvrt01

the result will show in one collum as:
No name in column
20
45
32
41

Hope this make sense to you

"johnjayp" <jonathon_phillips@hotmail.com> a écrit dans le message de
news:cf9371e6.0408100324.1942c61d@posting.google.c om...
> I am having trouble linking four count statements. Each statment is a
> count for a different table. The statements can be seen below;
>
> select count (*) from xwrsct01
> select count (*) from xwrmvt01
> select count (*) from xtrdlt01
> select count (*) from xtrvrt01
>
> I need the statement to return seperate values for each table.
>
> Any help would be appreciated.



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-29-2008, 03:54 AM
johnjayp
 
Posts: n/a
Default Re: sql

That has worked thanks.

"Emmanuel Petit" <emmanuel.petit15@wanadoo.fr> wrote in message news:<cfaq9d$99d$1@news-reader1.wanadoo.fr>...
> 2 differents ways to do it:
> 1/ select count(xwrsct01.name of one column of the table xwrsct01) as
> xwrsct01Count, count(xwrmvt01.name of one column of the table xwrmvt01) as
> xwrmvt01Count, count (xtrdlt01.name of one of collum of the table xtrdlt01)
> as xtrdlt01Count, count (xtrvrt01.name of one column of the table xtrvrt01)
> as xtrvrt01Count from xwrsct01 , xwrmvt01, xtrdlt01, xtrvrt01
>
> the result will show as :
> xwrsct01Count xwrmvt01Count xtrdlt01Count xtrvrt01Count
> 20 45 32
> 41
>
> 2/ select count (*) from xwrsct01
> union
> select count (*) from xwrmvt01
> union
> select count (*) from xtrdlt01
> union
> select count (*) from xtrvrt01
>
> the result will show in one collum as:
> No name in column
> 20
> 45
> 32
> 41
>
> Hope this make sense to you
>
> "johnjayp" <jonathon_phillips@hotmail.com> a écrit dans le message de
> news:cf9371e6.0408100324.1942c61d@posting.google.c om...
> > I am having trouble linking four count statements. Each statment is a
> > count for a different table. The statements can be seen below;
> >
> > select count (*) from xwrsct01
> > select count (*) from xwrmvt01
> > select count (*) from xtrdlt01
> > select count (*) from xtrvrt01
> >
> > I need the statement to return seperate values for each table.
> >
> > Any help would be appreciated.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 09:32 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com