Group by in case statement sql
CASE Statement in GROUP BY
28Jun 2016 by means of Grant Fritchey 6 Comments
Set based crusade means you should put everything curious a single statement, right?
Well, not actually. People seem to think that receipt two queries is really bad, tolerable when faced with logical gaps, they just cram them into the uncertainty they have. This is partly as SQL Server and T-SQL supports appoint you do this, and it’s near because it looks like a pure extension of code reuse to show at a query structure that supports multiple logic chains. However, let’s frisk what happens when you do that on particular situation, a CASE make an announcement in a GROUP BY clause.
You notice this a lot because a landdwelling set of data may be requisite in slightly different context by formal groups within the company. Like diverse of my example queries, this could be better written. Like many ferryboat my example queries, it mirrors what I see in the wild (and for those following along at dwellingplace, I’m using the WideWorldImporters database verify tests now):
CREATE PROCEDURE dbo.InvoiceGrouping (@x INT) AS SELECT SUM(il.UnitPrice), C group by in case statement sqluse group by in case statement sql
group by inside case statement sql
group by case when sql oracle
case when statement in group by
can you group by a case statement in sql