I’ve been burned by this one so many times it’s not funny. Although if you like seeing me get frustrated, then I guess it is funny.
Here’s the issue: you have a SQL SELECT statement that you’re using in a Cognos Report Studio report, and you’ve verified that it is syntactically correct. It runs fine in Studio Express, for example. But then you try to add a filter (also one that is syntactically correct) in Report Studio, and you get an error. The SQL SELECT statement is correct, the filter is correct, but enable the filter and if fails. What…?
Short answer: Don’t put “ORDER BY” sort statements in the SQL SELECT command. Your order statements should only occur in Report Studio.
Long answer:
The reason this errors out is that when you put in a filter in the report (not in the original SQL SELECT), Report Studio adds that filter to the end of the SELECT statement it constructs. So if the SQL is:
SELECT ApplicationName from R_Applications
And you add a filter like “[ApplicationName]=’something’”, then Cognos bundles them together and sends this request to the SQL server:
SELECT ApplicationName from R_Applications WHERE [ApplicationName]=’something’
If the statement in the original SQL is
SELECT ApplicationName from R_Applications ORDER BY ApplicationName
Then when Cognos sends the statement with the filter enabled it sends:
SELECT ApplicationName from R_Applications ORDER BY ApplicationName WHERE [ApplicationName]=’something’
Which is a syntax error: WHERE cannot come after ORDER BY.
Ta da!
February 29, 2008 at 11:47 am
So is that a Report Studio bug, or is it something that cannot reasonably be corrected and thus demands the care that you have denoted here?
February 29, 2008 at 1:09 pm
Not sure if it’s a “bug”, per se. It’s just the way they do things, and it’s just not well documented at all. The error message is particularly obscure, and gives no indication as to the cause or even where to start looking: all you see is that you enable a filter that is syntactically correct, run the report, get the error. Disable the filter, report runs fine. It’s very frustrating.
Of course, they could correct things by improving the error message, or being smarter on creating the SQL statement before sending it to the SQL server.