Cognos 10.2.1 to_date function - cognos-10

Report Studio Reports are recently migrated from Cognos 8.4.1 to Cognos 10.2.1.In cognos 10, to_date(timestamp) function is not working which was perfectly working in cognos 8.4.1. Any report which got following expression in the filter are failing in Cognos 10 but works fine in Cognos 8.
to_date(trunc([Presentation Layer].[Query Subject].[FROM_DATE])) >= ?fromDate?
FROM_DATE = date from data source(Oracle) which is of type timstamp
fromDate = is a report parameter passed in the query string
Can some one please advise the fix/work around on this issues. We are talking about several reports that got this issue.

Have you tried using the CAST() function? Usage would be cast([Presentation Layer].[Query Subject].[FROM_DATE],date). CAST is a Cognos-specific function which will be translated into the DB provider-specific function within the SQL sent to to the DB.

Related

Is it possible to pass a database field as parameter in SQL query in SAP Crystal Report?

Is it possible to pass a database field, for example MyTable.EmpoyeeID as a parameter in SQL query using Command? MyTable.EmpoyeeID value will be defined using ASP. net.
Sample:
SELECT FName, MName, LName FROM MyTable WHERE EmpoyeeID = MyTable.EmpoyeeID
option 1: yes, but you need to use aliases and, if memory serves the behavior tends to change across Crystal version. Google the topic of Crystal Reports, SQL Expressions, and Correlated Subqueries. You should find several in-depth threads.
option 2: use a 3rd-party UFL (User Function Library) that allows you to call arbitrary SQL statement you create inside a Crystal formula (not just SELECT statements are supported using that approach).

Stored Procedure works fine from SQL Mgt Studio but throws Invalid Object name #AllActiveOrders from MVC app

I can run the 'guts' of my stored procedure as a giant query.. just fine from SQL Management Studio. Furthermore, I can even right click and 'execute' the stored procedure - .. y'know.. run it as a stored procedure - from SQL Management Studio.
When my ASP.NET MVC app goes to run this stored procedure, I get issues..
System.Data.SqlClient.SqlException: Invalid object name '#AllActiveOrders'.
Does the impersonation account that ASP.NET runs under need special permissions? That can't be it.. even when I run it locally from my Visual Studio (under my login account) I also get the temp table error message.
EDIT: Furthermore, it seems to work fine when called from one ASP.NET app (which is using a WCF service / ADO.NET to call the stored procedure) but does not work from a different ASP.NET app (which calls the stored proc directly using ADO.NET)
FURTHERMORE: The MVC app that doesn't crash, does pass in some parameters to the stored procedure, while the crashing app runs the Stored Proc with default parameters (doesn't pass any in). FWIW - when I run the stored procedure in SQL Mgt. Studio, it's with default parameters (and it doesn't crash).
If it's of any worth, I did have to fix a 'String or Binary data would be truncated' issue just prior to this situation. I went into this massive query and fixed the temptable definition (a different one) that I knew to be the problem (since I had just edited it a day or so ago). I was able to see the 'String/Binary truncation' issue in SQL Mgt. Studio / as well as resolve the issue in SQL Mgt Studio.. but, I'm really stumped as to why I cannot see the 'Invalid Object name' issue in SQL Mgt. Studio
Stored procedures and temp tables generally don't mix well with strongly typed implementations of database objects (ado, datasets, I'm sure there's others).
If you change your #temp table to a #variable table that should fix your issue.
(Apparently) this works in some cases:
IF 1=0 BEGIN
SET FMTONLY OFF
END
Although according to http://msdn.microsoft.com/en-us/library/ms173839.aspx, the functionality is considered deprecated.
An example on how to change from temp table to var table would be like:
create table #tempTable (id int, someVal varchar(50))
to:
declare #tempTable table (id int, someval varchar(50))
There are a few differences between temp and var tables you should consider:
What's the difference between a temp table and table variable in SQL Server?
When should I use a table variable vs temporary table in sql server?
Ok. Figured it out with the help of my colleague who did some better Google-fu than I had done prior..
First, we CAN indeed make SQL Management Studio puke on my stored procedure by adding the FMTONLY option:
SET FMTONLY ON;
EXEC [dbo].[My_MassiveStackOfSubQueriesToProduceADigestDataSet]
GO
Now, on to my two competing ASP.NET applications... why one of them worked and one of them didn't? Under the covers, both essentially used an ADO.NET System.Data.SqlClient.SqlDataAdapter to go get the data and each performed a .Fill(DataSet1)
However, the one that was crashing was trying to get the schema in advanced of the data, instead of just deriving the schema after the fact.. so, it was this line of code that was killing it:
da.FillSchema(DataSet1, SchemaType.Mapped)
If you're struggling with this same issue that I've had, you may have come across forums like this from MSDN which are all over the internets - which explain the details of what's going on quite adequately. It had just never occurred to me that when I called "FillSchema" that I was essentially tripping over this same issue.
Now I know!!!
Following on from bkwdesign's answer about finding the problem was due to ADO.NET DataAdapter.FillSchema using SET FMTONLY ON, I had a similar problem. This is how I dealt with it:
I found the simplest solution was to short-circuit the stored proc, returning a dummy recordset FillSchema could use. So at the top of the stored proc I added something like:
IF 1 = 0
BEGIN;
SELECT CAST(0 as INT) AS ID,
CAST(NULL AS VARCHAR(10)) AS SomTextCol,
...;
RETURN 0;
END;
The columns of the select statement are identical in name, data type and order to the schema of the recordset that will be returned from the stored proc when it executes normally.
The RETURN ensures that FillSchema doesn't look at the rest of the stored proc, and so avoids problems with temp tables.

Crystal reports parameters using a command to an Oracle database

I am trying to create a report that has three optional parameters using a command in Crystal Reports 2008. The only one I can't get to work is the date parameter (seems Oracle does not treat dates the same as SQL Server).
I want the user to be able to pick and choose which parameter they would like to use; one, two, or all three. It works beautifully when I run it in TOAD and hard code the dates, but it will not run in Crystal reports using the syntax to create the parameters.
I have done this a thousand times in a SQL server environment but can't get it to work in Oracle.
The field is type is DATE in the Oracle table.
Here is the syntax from my Report command for the 3 parameters:
AND ( ( CLIL. ITEM_TAG IN ('{?tag}') OR CLS.DESCRIPTION IN( '{?desc}')
OR trunc (CLIL.ISSUE_DATE) BETWEEN to_date ('{?StartDate}', 'mm/dd/yyyy') and to_date ('{?EndDate}', 'mm/dd/yyyy' )))
Crystal reports doesn't accept the Oracle syntax.. you need to use the functions provided by the CR to do manuplations of dates... and then use that in CR.
Create a Start Date and End Date as date parameters in CR and then use those.
(CLIL.ISSUE_DATE) >= {?StartDate} and (CLIL.ISSUE_DATE) < {?EndDate}
Here start date and end date are Date datatype parameters.
if (CLIL.ISSUE_DATE) is a datetime parameter then use the function Cdate provided by the crystal.

nHibernate named query returns not all results

I have a few simple named queries with only joins, ant couple subselects. All of them ar working perfectly except one. The problem is, that when i run SQL code in Management Studio, i get 177 results, and when i run named query with the same SQL code, i get 20 results. I can't figure out why is that. I Call named query the as all other:
public IList<InstitutionIndexDTO> GetInstitutionIndexByWorkTimeSearch(int time, int institutionType)
{
IQuery query = GetCurrentSession()
.GetNamedQuery("GetInstitutionsListByTime")
.SetInt32("Type", institutionType)
.SetInt32("TimeUntilClose", time)
.SetResultTransformer(Transformers.AliasToBeanConstructor(typeof(InstitutionIndexDTO).GetConstructors()[0]));
return query.List<InstitutionIndexDTO>();
}
Even when i harcoded parameters in SQL, i still got the same result. I tried checking with Profiler, but generated SQL is perfect and in management studio returns all 177 results.
InstitutionIndexDTO is working correctly, because i use it with other named queries.
I have a working named query, and the one causing problems was made from that one, adding additional INNER JOIN and changing WHERE clause. Both queries returns same columns.
Maybe somebody has an idea, what i could have done wrong?
I tested my code and realised that this line is causing the problem:
(CASE WHEN (DATEPART(dw, GETDATE())) = 1 THEN 7 ELSE (DATEPART(dw, GETDATE()) - 1) END)
If i understand well, the problem is in DATEPART function. Has anybody encountered this problem?

Viewing results of a pipelined function in SQL*Plus or Oracle SQL Developer

How can I view the results returned by a pipelined function in Oracle SQL Developer ?
I'm invoking the function using a simple select..from dual like
select piaa_extract.FN_PIAA_EXTRACT('01-JAN-00','01-JAN-12') FROM DUAL
and the result I get is
IQCFINAL.REC_PIAA(IQCFINAL.REC_PIAA,IQCFINAL.REC_PIAA,.....,IQCFINAL.REC_PIAA)
Allround Automations' PL/SQL developer displays the results beautifully in a tabular format, but I do not have a license for the full version of PL/SQL developer.
SQL*Plus' output isn't very good either, though better than Oracle SQL Developer's.
Any thoughts ?
Typically, you'd use
select * from table(piaa_extract.FN_PIAA_EXTRACT('01-JAN-00','01-JAN-12'))
Does that work?

Resources