I need to embed a native oracle sql statement inside COGNOS framework manager. This link describes how to do it.
e.g:
select cust_name from cust where cust_id = '111'
http://businessintelligence.ittoolbox.com/groups/technical-functional/cognos8-l/native-query-in-framework-manager-query-subject-2374263
Now is there a way to embed an SQL inside COGNOS FM that also accepts a parameter.
e/g:
select cust_name from cust where cust_id = ?
You can use the prompt macro as described here:
Creating prompts with query macros
Your expression should look something like this:
select cust_name from cust where cust_id = #prompt('prmCutsId','integer')#
Ofcourse you can expand it by providing default value, or use the promptmany macro so supply list of values (and not just one value).
You can really do nice things with macros in Cognos, but you have to know exactly what you are doing.
Related
I am trying to connect an excel data table to an access query where the access 2010 query has a defined set of parameters ([StartDate] and [EndDate]). I need to pass parameters from Excel to Access to reduce the scope of the data which needs to be summarised from the granular data.
The Access Query is made up to summarise a granular data by date and various other groupings; this query due to the way I have to snapshot specific information requires a secondary query set which is a XTAB.
On both the Primary Query I want to Return and the XTAB I have a defined parameter e.g. [StartDate] and [EndDate] defined as Date/Time. This is used in the WHERE clause for both data sets on the ReportDate field.
When running this in access I am prompted for [StartDate] and [EndDate] and the results are displayed exactly as expected.
My query looks something like (and lets refer to this as the OUTPUT_QRY):
PARAMETERS [StartDate] DateTime, [EndDate] DateTime;
SELECT [TABLE_1].[ReportDate],
[TABLE_1].[GroupA] AS CATEGORY_A,
[TABLE_1].[GroupB] AS CATEGORY_B,
[TABLE_1].[GroupC] AS CATEGORY_C,
SUM([TABLE_1].[values]) TOTAL_VOLUME
SUM([XTAB_2].[0]) GROUP_0_VOLUME
SUM([XTAB_2].[1]) GROUP_1_VOLUME
FROM [TABLE_1]
INNER JOIN [XTAB_2] ON [XTAB_2].[SnapshotKEY] = [TABLE_1].[SnapshotKEY]
WHERE [TABLE_1].REPORT_DATE BETWEEN [StartDate] and [EndDate]
GROUP BY [TABLE_1].[ReportDate],
[TABLE_1].[GroupA] AS CATEGORY_A,
[TABLE_1].[GroupB] AS CATEGORY_B,
[TABLE_1].[GroupC] AS CATEGORY_C
XTAB_2 is a summary of related data snapshot information for the same level of data on the SnapshotKey. The main aim of OUTPUT_QRY is to summarise snapshot data we have at a higher level. Using a XTAB is more efficient than having 200+ calculated columns. XTAB_2 also contains the first line from the above query (PARAMETERS [StartDate] DateTime, [EndDate] DateTime) to also limit the scope of certain snapshot groupings we have.
Without the parameters XTAB_2 attempts to summarise all 6m rows of data before applying the inner join from TABLE_1 which takes significant time. The parameters are there to limit the scope of data to be converted into a crosstab query.
When I run this 'OUTPUT_QRY' it prompts for the [StartDate] and [EndDate], which I enter, and it clearly applies the Parameters to the where clause of OUTPUT_QRY and the where clause in the linked XTAB query. As above this works flawlessly in Access.
I need to provide a method to connect to this data from Excel. I have used the trick to go to Data -> Other Sources -> From Microsoft Query; Connect to the Database; Return any old standalone table; finally edit the data tables 'Connection Properties' Definition Table to:
SELECT OUTPUT_QRY.* FROM OUTPUT_QRY
I am prompted with:
[Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 2
So I try:
SELECT OUTPUT_QRY.* FROM OUTPUT_QRY WHERE 1=? AND 2=?
And now it states:
[Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 4
It seems like it's not passing whatever it is I want to pass into the defined parameters and now treating 1=? and 2=? as new parameters? I need the capability to refresh this data as/when needed between specific dates once we have completed processing data on a daily basis to enable an end user to query the millions of rows of information and have it in a nice layout so they can summarise/query further within their only available tool of excel.
Note, I am aware this should be solutioned in a more robust environment than Access 2010 but unfortunately due to restrictions this is the only solution available to us and have no other viable options. Any suggestions on this approach would be greatly appreciated.
Kind Regards,
I'm looking into using RedQueryBuilder for a web-based query builder. I want my users to be able to specify what data they want to retrieve in the select clause, but the demo site
only shows selecting a single table, rendering all the columns of that table in the result. Does RedQueryBuilder support building out a more robust select clause, like specifying which specific columns to retrieve including those joined from other tables?
I'm afraid not. The project just concentrates on defining a query to return rows not what to show in those rows.
The onTableChange callback would feed you the list of tables in the expression so could go from that to a list of available columns...
Would you want/need to alter the SQL query generated or just the display of the results?
Personally I'd be interested in changing the demo into a more useful query too although the scope of that could be huge.
Here is my query. I am new to Cognos and using Cognos 10. And I am having a bit difficulty in developing a report which uses a Sub Query and an Inner Join Query.
1.
SELECT ID, BATCH_DT, LOCIT FROM AOI.TEMP_BRICK
WHERE BATCH_DT < (SELECT MAX(DATE) FROM CALENDAR)
2.
SELECT A.ID, B.SAL FROM TABLE as A LEFT OUTER JOIN TABLE as B
WHERE A.ID=B.ID
First, you must understand that Cognos generates its own SQL. In order for it to do that, you must define relationships between tables in Cognos Framework Manager. Once that is done your report has 3 major parts, The Report Page(s), the Prompt Page(s) and the Query(s).
a.) Setup the CALENDAR and AOI.TEMP_BRICK tables in Cognos. You may want to define a relationship between TEMP_BRICK.BATCH_DT and CALENDAR.DATE (assuming your calendar has date records for every date that may be present in TEMP_BRICK).
b.) Next you would create a new List Report. You would grab your ID, BATCH_DT and DATE fields into the list. (Date would come from the calendar if you decided to link the two tables in step A, otherwise you use the BATCH_DT field in TEMP_BRICK.)
c.) You would open the Query pages and see that Cognos has already created one query, called Query1. You need to create a new query (we will call it qryMaxDate). That query would have one element, 'DATE' from CALENDAR. On the properties of the 'DATE' field in Data Items, you would chagne the 'Agregate Function' from None to 'Maximum'.
d.) Now edit your Query1, add a Filter on the Date from that query. In the Expression Definition, select the Queries tab and drag the 'DATE' field from your qryMaxDate. Should look something like this [Batch Date] = [qryMaxDate].[Date]
e.) You are done! Run the report. in this case, the user running the report is giving no input, so no Prompt page is necessary.
a.) Setup Table A and B in the Framework Manager. You need to define a relationship between Table A and B in Framework Manager via a Star Schema (define A.ID = B.ID and specify 1 to n, or n to 1).
b.) Create a new report and simply drag in elements from table a and table b. Their relationship is already defined in Framework manager, so there is no need to re-define it while writing reports.
Your second example is a great demonstration of the power of BI programs like Cognos. Report Authors dont need to fully understand the ways that two tables are joined... they simply pull out elements from each table and they work, as the relationships are already defined in the Framework.
The StringMapBase SQL table is the table that holds Option List values that have been added to an entity. When using an Advanced Find in CRM 2011, if you select a pick list column (Option List) value from an entity to be added to the resultset, the Advanced Find mechanism somehow auto-wires in the string value of the pick list from the StringMapBase table instead of showing the StringMapBase's Primary Key value that's actually stored on the record.
I'm in the process of creating SSRS reports that hinge on some Option List values:
// SQL psuedocode
Select...
...
Where Value = 'Some String Value of Interest'
However, I very much dislike the fact that, so far, it looks like I basically have to write in some ad-hoc SQL in order to get the applicable StringMapBase value. In order to do so, I have to hard-code some magic values, which I despise.
Does anyone know by what mechanism the CRM Advanced Find engine auto-wires these values in? Or does it simply do its own join to the StringMap system view or use a SPROC somewhere?
When you use the Filtered views (the only supported way to read data in your report) there will be an additional "logical" column for Bit, Picklist, and Lookup columns. For an attribute named "new_option" you should be able to add "name" to the end of the column name and query "new_optionname".
select new_option, -- Integer
new_optionname -- StringMap joins generated by Filtered Views
from Filterednew_test
I'm using MS Excel to get data from a MySQL database through ODBC.
I successfully get data using an SQL query. But now I want that query to be parameterized.
So I wonder If it is possible to use a cell value (a spreadsheet cell) as a parameter for such a query.
For example, for this query:
select name from user where id=1
I'd like to get the id value from, say, cell D4 in the spreadsheet.
Is that the proper approach to parameterize a query? and how can I do it?
Thanks.
I had the same problem as you, Noboby can understand me, But I solved it in this way.
SELECT NAME, TELEFONE, DATA
FROM [sheet1$a1:q633]
WHERE NAME IN (SELECT * FROM [sheet2$a1:a2])
you need insert a parameter in other sheet, the SQL will consider that information like as
database, then you can select the information and compare them into parameter you like.
If you are using microsoft query, you can add "?" to your query...
select name from user where id= ?
that will popup a small window asking for the cell/data/etc when you go back to excel.
In the popup window, you can also select "always use this cell as a parameter" eliminating the need to define that cell every time you refresh your data. This is the easiest option.
queryString = "SELECT name FROM user WHERE id=" & Worksheets("Sheet1").Range("D4").Value
The SQL is somewhat like the syntax of MS SQL.
SELECT * FROM [table$] WHERE *;
It is important that the table name is ended with a $ sign and the whole thing is put into brackets. As conditions you can use any value, but so far Excel didn't allow me to use what I call "SQL Apostrophes" (ยด), so a column title in one word is recommended.
If you have users listed in a table called "Users", and the id is in a column titled "id" and the name in a column titled "Name", your query will look like this:
SELECT Name FROM [Users$] WHERE id = 1;
Hope this helps.