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 ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| 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. |
| |||
| 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) |
| |||
| 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. |
| ||||
| 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. |