2 Generated SQL/MDX queries under a SQL query in IBM Cognos - sql

I have a report where a query named "Query1" is created using the default data items present in the package. When I look into the Tools ---> Show Generated SQL/MDX, IBM Cognos shows 2 generated Native SQL queries for the query named "Query1". How does 2 query get created --- Query1.0 & Query 1.1 ? Under what scenario does this happen? FYI --- The changes that is done in the environment is that a new model is added under a product family at the starting of this month. Could this be the reason why 2 SQL queries has been generated? Can someone explain what happens at the backend?

Generally, there are two reasons that you will see multiple separate queries in the generated SQL:
Some or all of the objects referenced in the Cognos query don't have defined relationships to each other in the model/package
The objects referenced in the Cognos query come from two or more different data sources
In the case of 1 you will end up with a cross join. In the case of 2, Cognos will retrieve the data separately from each source and then stitch them together in memory on the Cognos report server.
There may be other reasons that more than one separate query is shown in generated SQL but these two are the ones I've come across in my work.

Related

IBM SPSS How to import a Custom SQL Database Query

I am looking to see if the capability is there to have a custom SSMS sql query imported in SPSS (Statistical Package for the Social Sciences). I would want to build syntax that generates this query as my new dataset that I can then continue my scripted analysis. I see the basic query capability of one table from a Sql Server but I would like to create a query that joins to many tables. I anticipate the query to be a bit complex with many joins and perhaps data transformations.
Has anybody had experience or a solution to this situation?
I know I could take the query and make a table of it that SPSS can then connect to but my data changes daily and I would need a job in another application to refresh this table before my SPSS syntax would pull it and I would like to eliminate that first step by just having the query that grabs the data at the beginning of my syntax.
Ultimately I am looking to build out my SPSS syntax and schedule it in the Production Facility to run daily.

Impala Show Tables

I know in Impala (and other databases) I can run both of the following:
SHOW DATABASES
SHOW TABLES
I also know I can add optional LIKE or IN arguments e.g. to show me all the tables in database Bananas I could write:
SHOW TABLES IN Bananas
What I really want to know is a way of returning all the tables in the databases without having to recurse through (also showing database name and table name in separate fields.
I'll be running this via impala shell so I'd have to first return back all the database names and then produce a script line per database to give me the tables.
It's not a problem to do this as such, I just can't help wondering there must be a better way to end up with:
Unfortunately not yet. Impala will eventually support this by exposing tables for schema metadata (e.g. ANSI INFORMATION_SCHEMA), and IMPALA-1761 tracks that feature request.

Teradata SQL & cognos. How can I customize Cognos to accept a customized & more efficiently performing SQL

RIght at the outset I'd like to say that I am NOT a Cognos Guy .So I have totally disconnected myself from developing cognos cubes / reports whatever you want to call it.
There are COGNOS queries auto generated - very badly written that will cause the Teradata ( DBS 15.1.x ) system to Hog on spool & CPU . I can tune them beautifully after I pull them out from DBQL. I want to know HOW can I implement Custom Queries that can be run periodically as batch reports instead of Cognos auto-generating these queries.
E.g. You create a cube - its writes code behind it and then you can open the code and write custom code that is equivalent to the original code but performs a lot better. Then when you open the cube again - it remembers there is a custom SQL and runs that instead of its own auto generated SQL . This is just how I imagine one way it can do it but again- I am not a cognos resource so pl dont flag me down for lack of knowledge. That is exactly what I am trying to get an idea about
Thanks for bearing with me
In Framework Manager you can create one Query Subject with complex query inside. Do not import tables etc. Just create QS in put your query inside.
You need to use stored procedure to return your expected data and add it to Model.
Then instead of using couple of tables in Cognos report studio (and joins), add one query and point it to your stored procedure. This way your Cognos report will execute the procedure instead of generating query (which may not be efficient in many cases)

SSRS report builder 2.0 How to link 2 servers and run in one dataset

I am trying to find a way of linking data from two servers in SSRS report builder 2.0
ultimately using one dataset to query 2 databases in 2 different servers.
The SQL that i have is very basic as shown below and i can run the query easily in SQL management studio.
select * from
[server1].[DES].[dbo].[Daily] dr
LEFT JOIN [server2].[VES].[dbo].[Rou] mr
ON dr.ID = mr.id
Also the access i have to the reporting server is read only so i cant really make any administrative changes to the configuration.
I have explored the connection string to create a connection but it only allows me to connect to one server for each dataset. what i am trying to do is use one dataset
Any help will be greatly appreciated as i am a junior in SQL and SSRS
Using SSRS and MS SQL 2008 R2
if you executing this query from your SSMS it means this other server
is a linked server. then it should be no different to execute it from
SSRS.
Yes it is right you can only add one server to your data source of
your dataset whether its a shared data source or embedded.
But for instance if you have a data source pointing to say Server A
when you executing queries which will be pulling data from Server A
and also from server B you will Use fully Qualified name for the
Objects from server B and two part name from server A.
something like this ...
SELECT *
FROM Schema.Table_Name A INNER JOIN [ServerNameB].DataBase.Schema.TableName B
ON A.ColumnA = B.ColumnA
obviously ServerB has to be a Linked Server.
I can think of two possible solutions
Option 1:
Creating a stored procedure on server1 (With a query accessing the another server). And call this stored procedure from SSRS (Dataset).
Option 2:
Create two dataset with two different connection strings on the RDL (one for Server1 and another for Server2).
Use the "LookUpDataSet" function in Report Builder to merge the results using the key fields.
Option 2 is preferable.

Excel query showing different result than SSMS query

I have had an odd error I cannot explain. Basically, I am running a query to my SQL database using excel and am having non-existent data pop up when it comes to a very particular order in my database.
Here is a simple query surrounding this order:
select * from OR200100 where OR200100.OR20001='0000793605'
Here is the output in EXCEL
And here is the same output in SQL
what is happening here? How could the same query generate 2 different results?
Run SQL Server Profiler against the database if you can, then compare the output to the sql query that you are running in ssms.
OK, so it's SQL Server then, that's important because different SQL products can have very different idiosyncrasies and controls.
The next things to check are these:
Is OR200100 a Table or a View? If it's a view then post it's code.
Are you using the same Login/account from both Excel and SSMS?
Are you sure that you are connecting to the same Server and Database? SSMS tells you what you are connected to, but client apps like Excel do not and it is very common for this type of problem to be caused by the app connecting to a Dev or QA version of the database. See here for some of the different ways that this can happen:
So I had a very similar problem, my query was grouping by week numbers. What I found was that one of the queries had set datefirst 5 set whilst the other didn't. I guess the key thing here is make sure, if you are using any SET operations in your ssms queries, these are identical to those in the Excel query string.