Académique Documents
Professionnel Documents
Culture Documents
The information in this document is provided as-is. The information is believed to be correct, but future releases of the BusinessObjects software may render suggestions or strategies provided here useless, inappropriate, or incompatible. All information is copyright integra solutions, inc, and may not be redistributed in any form or via any media electronic or otherwise without obtaining prior written consent from the author(s).
The select clause is the same in each case, but the FROM and WHERE are different. Using the DataProviderSQL() function, we can look at the SQL text and determine which context is being used.
Function Fun!
The following functions will be used in this solution: DataProvider() Argument: variable name Return: data provider name Argument: data provider name Return: SQL from data provider Arguments: String to search, text item to find Return: integer showing position of found item, returns zero (0) if not found Argument: numeric value Return: Argument = 0, return 0 Argument > 0, return 1 Argument < 0, return 1 Argument is null, return null
DataProviderSQL()
Pos()
Sign()
To finish everything off, the power of BusinessObjects If logic will be used as well.
to get this information. Once we have the name of the data provider, the next step is to retrieve the SQL for that query. This is where the DataProviderSQL() function comes in. With the name of the data provider, the SQL from the query can be found by using:
=DataProviderSQL( DataProvider(<Customer>) )
The result of this formula would match the SQL that was shown earlier in this document. Thats a little much for a user to work through, so Ill go a few more steps to isolate the actual context name. Reviewing the Where clause for each context shows the following tables: Sales Context
Resort, Customer, Service_Line, Service, Invoice_Line, Sales
Reservations Context
Resort, Customer, Service_Line, Service, Reservation_Line, Reservations
Note that the first four tables are the same in either case. Only the last two are different! So, if I find the table Sales, I am in the Sales context. The presence of the Reservations table implies that the Reservations context was selected. (Please note that it is not required that the table names match the context names in any universe.)
The information in this document is provided as-is. The information is believed to be correct, but future releases of the BusinessObjects software may render suggestions or strategies provided here useless, inappropriate, or incompatible. All information is copyright integra solutions, inc, and may not be redistributed in any form or via any media electronic or otherwise without obtaining prior written consent from the author(s).
will return the point in the SQL where the word Reservation was found. If the word is not found (meaning that the Sales context was selected) then this formula will return the value of zero (0). Somehow this has to be useful! By using the If feature of BusinessObjects, we can use the value returned by Pos() and make a decision on which context name to display. If the word Reservation does not appear in the data provider SQL, then we assume that the Sales context has been selected. If the word Reservation does appear, then we assume the Reservation context was the one chosen. I got a little fancy at this point. I could have used:
=If Pos(DataProviderSQL(DataProvider(<Customer>)) ,"Reservation") >0 Then "Reservation" Else "Sales"
Really, the functionality of both of these formulas is the same. The Sign() function is used to eliminate all but three possible values, -1, 0, or 1. Since I know the Pos() function can never return a negative number, then really what I have is a binary flag: zero or one. I tend to like this sort of result because I can use it in an Alerter, a Filter, or any other feature of BusinessObjects. The final result is displayed in a BusinessObjects report that can be downloaded along with this document.
Possible Problem
This is not a perfect solution. What if the word Reservation appears somewhere else in the SQL? We would want to make sure that the word is found only in the From clause of the SQL, and nowhere else. Without going into a full explanation of the details, here is a set of variables that would solve this problem by first isolating the From clause of the SQL before looking for a specific table name. Variable
Data Provider SQL From Clause Start From Clause Stop From Clause SQL
Formula
=DataProviderSQL(DataProvider(<Customer>)) =Pos(<Data Provider SQL> ,"FROM")+4 =Pos(<Data Provider SQL> ,"WHERE")-1 =SubStr(<Data Provider SQL> ,<From Clause Start> ,<From Clause Stop>-<From Clause Start>) = If Sign( Pos(<From Clause SQL> ,"Reservation") ) <> 0 Then "Reservation" Else "Sales"
Context Name
The variable expression is built in steps to allow for easier debugging. Also, note in the formula for From Clause SQL the variable <From Clause Start> is used twice. So, with careful construction of our variables, we can display the name of a context on a user report.
The information in this document is provided as-is. The information is believed to be correct, but future releases of the BusinessObjects software may render suggestions or strategies provided here useless, inappropriate, or incompatible. All information is copyright integra solutions, inc, and may not be redistributed in any form or via any media electronic or otherwise without obtaining prior written consent from the author(s).