Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Problem with totalize per quarter
Message
From
21/08/2016 03:54:24
 
 
To
20/08/2016 16:27:22
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2012
OS:
Windows 10
Network:
Windows Server 2012
Miscellaneous
Thread ID:
01639700
Message ID:
01639715
Views:
66
This message has been marked as a message which has helped to the initial question of the thread.
Hi, Christian,

Glad you took a crack at it. PIVOT is perfect for something like this.

As Naomi pointed out in her reply, you want to be careful about using a WHERE clause on a table involved in an OUTER JOIN.

Stripped down to the bare essentials....if you do this

SELECT *
FROM MasterTable
LEFT OUTER JOIN ChildTable ON MasterTable.ProductPK = ChildTable.ProductFK
WHERE ChildTable.DollarAmount > 100

in other words, if you query from Table A....and then do a left outer join to Table B....and then use a WHERE clause on a column from Table B....effectively you lose the behavior of an OUTER JOIN and you've turned the query into an INNER JOIN. Probably not your intention.

So you need to "localize" (my expression) the condition...

SELECT *
FROM MasterTable
LEFT OUTER JOIN ChildTable ON MasterTable.ProductPK = ChildTable.ProductFK AND ChildTable.DollarAmount > 100


And on her other point, if you have date indexes, you'll want to use BETWEEN with a date range, as opposed to using DATEPART with Year. You'll potentially get better performance.
Previous
Reply
Map
View

Click here to load this message in the networking platform