|
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 TABLENAME
One option that doesn't rely on any rollup or compute magic...
|
|
|
|
|
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)
|
|
|
|
|
What is wrong with group by and count
Select Fieldname, Count(*)
from Tablename
Group By FieldName
Never 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...
|
|
|
|
|
Missed that, it did seem too simplistic to me!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
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
|
|
|
|