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. sql server 2008 query,

sql server 2008 query,

Scheduled Pinned Locked Moved Database
databasesql-serverhelpsysadmintutorial
8 Posts 4 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.
  • G Offline
    G Offline
    gavindon
    wrote on last edited by
    #1

    Ok here is my issue. I know how to do a count, count distinct and all that. I have a column in my table that has 3 different values(only three, never more), so every row that is entered with have one of those three values. The values are, Bundle Bowed Board Jam I am trying to figure out how to write a query that will count how many times of EACH value there is in the table. ie... 55 bundles... 10 bowed boards.... 5 jams... for some reason I just cant get this one in my head. any help to be had? I do need it to be a single query as it is going in a dataset for a SSRS report Matrix.

    Treat stressful situations like a dog, if you can't eat it, play with it or screw it, then just piss on it and walk away. Be careful which toes you step on today, they might be connected to the foot that kicks your butt tomorrow.

    _ M G 3 Replies Last reply
    0
    • G gavindon

      Ok here is my issue. I know how to do a count, count distinct and all that. I have a column in my table that has 3 different values(only three, never more), so every row that is entered with have one of those three values. The values are, Bundle Bowed Board Jam I am trying to figure out how to write a query that will count how many times of EACH value there is in the table. ie... 55 bundles... 10 bowed boards.... 5 jams... for some reason I just cant get this one in my head. any help to be had? I do need it to be a single query as it is going in a dataset for a SSRS report Matrix.

      Treat stressful situations like a dog, if you can't eat it, play with it or screw it, then just piss on it and walk away. Be careful which toes you step on today, they might be connected to the foot that kicks your butt tomorrow.

      _ Offline
      _ Offline
      _Damian S_
      wrote on last edited by
      #2

      select sum(iif(FIELDNAME = 'Bundle', 1, 0)) as NumBundles,
      sum(iif(FIELDNAME = 'Bowed Board', 1, 0)) as NumBowedBoards,
      sum(iif(FIELDNAME = 'Jam', 1, 0)) as NumJams
      from TABLENAME

      One option that doesn't rely on any rollup or compute magic...

      Quad skating his way through the world since the early 80's... Booger Mobile - My bright green 1964 Ford Falcon - check out the blog here!! | If you feel generous - make a donation to Camp Quality!!

      G 1 Reply Last reply
      0
      • _ _Damian S_

        select sum(iif(FIELDNAME = 'Bundle', 1, 0)) as NumBundles,
        sum(iif(FIELDNAME = 'Bowed Board', 1, 0)) as NumBowedBoards,
        sum(iif(FIELDNAME = 'Jam', 1, 0)) as NumJams
        from TABLENAME

        One option that doesn't rely on any rollup or compute magic...

        Quad skating his way through the world since the early 80's... Booger Mobile - My bright green 1964 Ford Falcon - check out the blog here!! | If you feel generous - make a donation to Camp Quality!!

        G Offline
        G Offline
        gavindon
        wrote on last edited by
        #3

        That didn't quite work but it did set me on the right train of thought and for that I thank you much. Solved with a couple of simple views combined in a query and let the SSRS report handle the count.. And I can easily reuse the views in a couple of other reports for different level of management..

        Treat stressful situations like a dog, if you can't eat it, play with it or screw it, then just piss on it and walk away. Be careful which toes you step on today, they might be connected to the foot that kicks your butt tomorrow.

        _ 1 Reply Last reply
        0
        • G gavindon

          That didn't quite work but it did set me on the right train of thought and for that I thank you much. Solved with a couple of simple views combined in a query and let the SSRS report handle the count.. And I can easily reuse the views in a couple of other reports for different level of management..

          Treat stressful situations like a dog, if you can't eat it, play with it or screw it, then just piss on it and walk away. Be careful which toes you step on today, they might be connected to the foot that kicks your butt tomorrow.

          _ Offline
          _ Offline
          _Damian S_
          wrote on last edited by
          #4

          No worries... Glad someone's making progress today... I'm still in SQL hell... (See post below)

          Quad skating his way through the world since the early 80's... Booger Mobile - My bright green 1964 Ford Falcon - check out the blog here!! | If you feel generous - make a donation to Camp Quality!!

          1 Reply Last reply
          0
          • G gavindon

            Ok here is my issue. I know how to do a count, count distinct and all that. I have a column in my table that has 3 different values(only three, never more), so every row that is entered with have one of those three values. The values are, Bundle Bowed Board Jam I am trying to figure out how to write a query that will count how many times of EACH value there is in the table. ie... 55 bundles... 10 bowed boards.... 5 jams... for some reason I just cant get this one in my head. any help to be had? I do need it to be a single query as it is going in a dataset for a SSRS report Matrix.

            Treat stressful situations like a dog, if you can't eat it, play with it or screw it, then just piss on it and walk away. Be careful which toes you step on today, they might be connected to the foot that kicks your butt tomorrow.

            M Offline
            M Offline
            Mycroft Holmes
            wrote on last edited by
            #5

            What is wrong with group by and count

            Select Fieldname, Count(*)
            from Tablename
            Group By FieldName

            Never underestimate the power of human stupidity RAH

            _ 1 Reply Last reply
            0
            • M Mycroft Holmes

              What is wrong with group by and count

              Select Fieldname, Count(*)
              from Tablename
              Group By FieldName

              Never underestimate the power of human stupidity RAH

              _ Offline
              _ Offline
              _Damian S_
              wrote on last edited by
              #6

              The OP said they already knew about count, so I assumed they were wanting the three values on a single line...

              Quad skating his way through the world since the early 80's... Booger Mobile - My bright green 1964 Ford Falcon - check out the blog here!! | If you feel generous - make a donation to Camp Quality!!

              M 1 Reply Last reply
              0
              • _ _Damian S_

                The OP said they already knew about count, so I assumed they were wanting the three values on a single line...

                Quad skating his way through the world since the early 80's... Booger Mobile - My bright green 1964 Ford Falcon - check out the blog here!! | If you feel generous - make a donation to Camp Quality!!

                M Offline
                M Offline
                Mycroft Holmes
                wrote on last edited by
                #7

                :doh: Missed that, it did seem too simplistic to me!

                Never underestimate the power of human stupidity RAH

                1 Reply Last reply
                0
                • G gavindon

                  Ok here is my issue. I know how to do a count, count distinct and all that. I have a column in my table that has 3 different values(only three, never more), so every row that is entered with have one of those three values. The values are, Bundle Bowed Board Jam I am trying to figure out how to write a query that will count how many times of EACH value there is in the table. ie... 55 bundles... 10 bowed boards.... 5 jams... for some reason I just cant get this one in my head. any help to be had? I do need it to be a single query as it is going in a dataset for a SSRS report Matrix.

                  Treat stressful situations like a dog, if you can't eat it, play with it or screw it, then just piss on it and walk away. Be careful which toes you step on today, they might be connected to the foot that kicks your butt tomorrow.

                  G Offline
                  G Offline
                  gvprabu
                  wrote on last edited by
                  #8

                  Hi Its simple Use COUNT Function... like as follows

                  SELECT CAST(ISNULL(COUNT(ProdType),0) AS VARCHAR(10)) + ' '+ ProdType FROM ProdDtls GROUP BY ProdType

                  Regards, GVPrabu

                  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