Friday, May 8, 2009
Business Objects PRUNE and TRACE functions
Nested SQL, Derived Table in Business Objects Universe, Multiple joins between tables
For example: A sales area is determined by a BrokerID (has it's own table), Company (has it's own table) and StateID (has it's own table). Now, these 3 fields/columns need to connect to a 4th table to pull proper information about sales area (i.e. Sales Area Number, Sales Reps, Sales Region, Sales regional manager and so on)--and this 4th table also has BrokerID, Company and StateID. In other words, I have to connect 3 columns from 3 different table to this 4th table. It's easy, so don't be scared. :)
In a Business Objects Universe, you could simply drag and join the relationship between tables and break the loops by creating aliases and/or contexts. But, if you ever come across nasty situation like this and want to avoid the never ending aliases and contexts, simply use a derived table. Though this code is for a Crystal Reports, it applies to universe scenario too.
Select * -- everything
From
-- dbo.CO_Contract AS C -- Need to connect to 2 (depended) columns from this table
(
Select
C2.PropertyAccountID,
C2.Company,
C2.StateID,
A.StateID,
-- Column 1 is native (C2.Company) – which becomes C.Company
-- and Column 2 is from CO_Address table - A.StateID
-- A.StateID becomes C.StateID, because this entire nested query is named ‘C’
From dbo.CO_Contract AS C2
Left Join dbo.CO_Address AS A ON
C2.AddressID = A.CO_ID
) C -- Again, this is the nested query and it's named as 'C'
-- DOUBLE JOINS --
Left Join dbo.CO_
On C.PropertyAccountID = RP.PropertyAccountID AND RP.RE1Flag = 'Y'
--- TRIPPLE JOINS ---
-- joining to ‘BSA’, 2 joins from ‘C’ and one join from ‘RP’
-- In an Universe, query such as this, used in a Derived table, will solve many loops (and traps)
Left Join dbo.CO_
On RP.PartyID = BSA.BrokerID
And C.Company = BSA.Company
And C.StateID = BSA.StateID
------------------------------------------------------------------------