sql

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • johnjayp

    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.
  • Hugo Kornelis

    #2
    Re: sql

    On 10 Aug 2004 04:24:35 -0700, johnjayp wrote:
    [color=blue]
    >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.[/color]

    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)

    Comment

    • Emmanuel Petit

      #3
      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_phill ips@hotmail.com > a écrit dans le message de
      news:cf9371e6.0 408100324.1942c 61d@posting.goo gle.com...[color=blue]
      > 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.[/color]


      Comment

      • johnjayp

        #4
        Re: sql

        That has worked thanks.

        "Emmanuel Petit" <emmanuel.petit 15@wanadoo.fr> wrote in message news:<cfaq9d$99 d$1@news-reader1.wanadoo .fr>...[color=blue]
        > 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_phill ips@hotmail.com > a écrit dans le message de
        > news:cf9371e6.0 408100324.1942c 61d@posting.goo gle.com...[color=green]
        > > 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.[/color][/color]

        Comment

        Working...