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,
Related
I'm creating a compliance mailing for my organization, the mailing will include merge fields that identify the office location, physician, and SiteId. The mailing will also include a table of information that is dependent upon the particular SiteId.
I'd like to use the import table function of MS word and set up a query that references a merged field (SiteId) so that the inserted tables populate the appropriate data for the particular site. I'm unable to do this.
How can I set up this document so that I can import only records from my source (an ms access query) that match the SiteId merge field?
Word's mail merge does not support one-to-many relationships. There are ways to coerce it, but only one of them can yield a table as a result and over the years it has become less and less reliable as Microsoft has not regarded it as important enough to maintain...
What you need to do is set up a query that provides ONLY the information you want displayed in the table, plus the key (SiteId). It's best to sort it so that all the SiteId entries list together, and are in the order the data will come through in the mail merge data source.
On the Insert tab go to Text/Quick Parts/Insert Field and select the Database field from the list in the dialog box. Click "Insert Database" and follow the instructions in the dialog box to link in the data. Be sure to set the Query Options to filter on the first SiteId from the data source. When you "Insert Data" make sure to choose the option to "Insert as a field".
This inserts a DATABASE field in the document which you can see by toggling field codes (Alt+F9). The field code can be edited and what you need to do is substitute the literal SiteId value you entered for the query with its corresponding MergeField.
When you execute the merge to a new document that should generate a table for each data record corresponding to the SiteId for the record. But, as I said, Microsoft hasn't done a great job of maintaining this, so it may require quite a bit of tweaking and experimenting.
If the results are not satisfactory then you should give up the idea of mail merge and use automation code to generate and populate the documents.
You can find more (albeit somewhat out-dated) information on this topic at http://homepage.swissonline.ch/cindymeister/mergfaq1.htm
I have a report that is up and running but I need to restrict the data on a parameter that takes multiple string-valued staff codes.
I created a parameter called Practioner which is a text type, ticked on Allow Multiple values and also on Visible.
In the available values, I made this code come from the field called mbillaty from the dataset3 under the Get values from a query option. I've checked data3 is fine in SQL server.
3.Now, I've gone to my dataset1 where all the reporting data sits then put the parameter, with the name ? and =Join(Parameters!Practitioner.Value,", ") for the parameter value. Then in the query, in the where clause, I've put: ......mbility in (?)
What should this SSRS be interpreting as is : .......mbility in ('AAB','KKR','RDR'), if the user picked these three staffs.
When I run the report, it definitley works when I check one of the practioners, but as soon as I more than one, the report wouldn't run. It does not return any error, but just the header shows, which I think means that no data is found.
Experts, do you see where I've gone wrong with this?
Thanks
If you're able to create UDFs, this link might be helpful. How do I split a string so I can access item x?
The parameter would be parsed in the SQL/function, and SSRS would simple pass the concatenated string.
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