sql server 2008 query,
-
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.
-
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.
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 TABLENAMEOne 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!!
-
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 TABLENAMEOne 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!!
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.
-
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.
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!!
-
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.
What is wrong with group by and count
Select Fieldname, Count(*)
from Tablename
Group By FieldNameNever underestimate the power of human stupidity RAH
-
What is wrong with group by and count
Select Fieldname, Count(*)
from Tablename
Group By FieldNameNever underestimate the power of human stupidity RAH
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!!
-
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!!
:doh: Missed that, it did seem too simplistic to me!
Never underestimate the power of human stupidity RAH
-
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.