July 24, 2018 at 12:54 am
select
Country
, Contacttitle
, COUNT(ContactTitle) as Count
,CASE WHEN GROUPING_ID() = 0 THEN ''
WHEN GROUPING_ID() = 1 THEN 'Subtotal for << Country >>'
END AS Legend
from dbo.customers
group by ROLLUP(country, ContactTitle)
What im missing in the syntax.
July 24, 2018 at 2:01 am
GG_BI_GG - Tuesday, July 24, 2018 12:54 AMselect
Country
, Contacttitle
, COUNT(ContactTitle) as Count
,CASE WHEN GROUPING_ID() = 0 THEN ''
WHEN GROUPING_ID() = 1 THEN 'Subtotal for << Country >>'
END AS Legend
from dbo.customers
group by ROLLUP(country, ContactTitle)What im missing in the syntax.
Kindly post at least minimum information to answer your question.
Saravanan
July 24, 2018 at 6:06 am
GG_BI_GG - Tuesday, July 24, 2018 12:54 AMselect
Country
, Contacttitle
, COUNT(ContactTitle) as Count
,CASE WHEN GROUPING_ID() = 0 THEN ''
WHEN GROUPING_ID() = 1 THEN 'Subtotal for << Country >>'
END AS Legend
from dbo.customers
group by ROLLUP(country, ContactTitle)What im missing in the syntax.
We don't have your tables to work with, and you haven't supplied any sample data, either. What; exactly; could we possibly do to help, given nothing to work with? About the only thing I can ask is why are you doing a count on a column you are grouping by...
Steve (aka sgmunson) 🙂 🙂 🙂
Rent Servers for Income (picks and shovels strategy)
July 24, 2018 at 6:31 am
Grouping_ID doesn't work like that, you need to specify the groupings in its argument list. Although personally for such a simple case I'd just use Grouping as it's a bit easier to understand and you don't need the added complexity if you've only got a single level to distinguish between.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply