Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. SELECT COUNT for individual rows

SELECT COUNT for individual rows

Scheduled Pinned Locked Moved Database
databasesysadminhelp
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Nino_1
    wrote on last edited by
    #1

    Hi, I'm trying to select the COUNT for individual rows within T-SQL while performing a join as follows:

    select count(a.officer as officer, e.open_date as opened, e.close_date as closed, j.can_date as cancelled) from
    escrow e inner join a10 a on e.escrow = a.escrow inner join e120 j on e.escrow = j.escrow group by a.officer, close_date, open_date, j.can_date

    Getting the following error while atempting this query: Server: Msg 170, Level 15, State 1, Line 3 Line 3: Incorrect syntax near ','. Is this possible in T-SQL Thanks, Nino

    E 1 Reply Last reply
    0
    • N Nino_1

      Hi, I'm trying to select the COUNT for individual rows within T-SQL while performing a join as follows:

      select count(a.officer as officer, e.open_date as opened, e.close_date as closed, j.can_date as cancelled) from
      escrow e inner join a10 a on e.escrow = a.escrow inner join e120 j on e.escrow = j.escrow group by a.officer, close_date, open_date, j.can_date

      Getting the following error while atempting this query: Server: Msg 170, Level 15, State 1, Line 3 Line 3: Incorrect syntax near ','. Is this possible in T-SQL Thanks, Nino

      E Offline
      E Offline
      Ennis Ray Lynch Jr
      wrote on last edited by
      #2

      select count(*) should give you the results you want. Count only counts the number of rows in a set. Using the field really doesn't do much unless you use distinct. A man said to the universe: "Sir I exist!" "However," replied the Universe, "The fact has not created in me A sense of obligation." -- Stephen Crane

      E 1 Reply Last reply
      0
      • E Ennis Ray Lynch Jr

        select count(*) should give you the results you want. Count only counts the number of rows in a set. Using the field really doesn't do much unless you use distinct. A man said to the universe: "Sir I exist!" "However," replied the Universe, "The fact has not created in me A sense of obligation." -- Stephen Crane

        E Offline
        E Offline
        Ennis Ray Lynch Jr
        wrote on last edited by
        #3

        SELECT a.officer as officer, e.open_date as opened, e.close_date as closed, j.can_date as cancelled, count(*) as ct FROM escrow e inner join a10 a on e.escrow = a.escrow inner join e120 j on e.escrow = j.escrow group by a.officer, close_date, open_date, j.can_date GROUP BY a.officer, a.open_date, a.close_date, a.can_date A man said to the universe: "Sir I exist!" "However," replied the Universe, "The fact has not created in me A sense of obligation." -- Stephen Crane

        N 1 Reply Last reply
        0
        • E Ennis Ray Lynch Jr

          SELECT a.officer as officer, e.open_date as opened, e.close_date as closed, j.can_date as cancelled, count(*) as ct FROM escrow e inner join a10 a on e.escrow = a.escrow inner join e120 j on e.escrow = j.escrow group by a.officer, close_date, open_date, j.can_date GROUP BY a.officer, a.open_date, a.close_date, a.can_date A man said to the universe: "Sir I exist!" "However," replied the Universe, "The fact has not created in me A sense of obligation." -- Stephen Crane

          N Offline
          N Offline
          Nino_1
          wrote on last edited by
          #4

          Thanks for your post, Actually i'm attempting to get the count for each individual row and display it through QA. Thanks, Nino

          C 1 Reply Last reply
          0
          • N Nino_1

            Thanks for your post, Actually i'm attempting to get the count for each individual row and display it through QA. Thanks, Nino

            C Offline
            C Offline
            Colin Angus Mackay
            wrote on last edited by
            #5

            Nino_1 wrote:

            Actually i'm attempting to get the count for each individual row and display it through QA

            Then the count will always be 1. So I suspect there is a gulf of comprehension somewhere: What do you mean by "each individual row"?


            Scottish Developers events: * .NET debugging, tracing and instrumentation by Duncan Edwards Jones and Code Coverage in .NET by Craig Murphy * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog

            N 1 Reply Last reply
            0
            • C Colin Angus Mackay

              Nino_1 wrote:

              Actually i'm attempting to get the count for each individual row and display it through QA

              Then the count will always be 1. So I suspect there is a gulf of comprehension somewhere: What do you mean by "each individual row"?


              Scottish Developers events: * .NET debugging, tracing and instrumentation by Duncan Edwards Jones and Code Coverage in .NET by Craig Murphy * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog

              N Offline
              N Offline
              Nino_1
              wrote on last edited by
              #6

              Hi Colin, here's what i came up with:

              select distinct a.officer as Officer, d.close_date as [Date], count(d.open_date)as [Open], count(d.close_date) as Closed, count(can_date)as Cancelled
              from a10 a inner join escrow d on a.escrow = d.escrow inner join e120 j on j.escrow = d.escrow where a.officer is not null group by a.officer, d.close_date

              Nino

              C 1 Reply Last reply
              0
              • N Nino_1

                Hi Colin, here's what i came up with:

                select distinct a.officer as Officer, d.close_date as [Date], count(d.open_date)as [Open], count(d.close_date) as Closed, count(can_date)as Cancelled
                from a10 a inner join escrow d on a.escrow = d.escrow inner join e120 j on j.escrow = d.escrow where a.officer is not null group by a.officer, d.close_date

                Nino

                C Offline
                C Offline
                Colin Angus Mackay
                wrote on last edited by
                #7

                That doesn't help me much. For each of the columns you have a COUNT() on it will always return 0 or 1 (counting each non-null, and since you don't have anything to group the aggregation by it there will always be just one row to be counted) Give me an example with data in your table and what you'd like the output to be - That will be helpful.


                Scottish Developers events: * .NET debugging, tracing and instrumentation by Duncan Edwards Jones and Code Coverage in .NET by Craig Murphy * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups