Cognos - Promptmany with default selection 'ALL' not working - cognos

I have a report that uses SQL Query. I have a promptmany macro in the SQL:
#promptmany('countryParam', 'string', 'and 1=1' , 'and s.country in (', 'countryParam', ' )')#
This prompt has a default value and 1=1 which should be passed if no value is selected.
On the prompt page, I have the prompt which displays all the countries.
I want the prompt to show All at the top of the list of countries in the prompt box. When the user selects All , no value should be passed in the SQL.
I have tried static choice to use blank and display to use All, but it passes blank value in the sql.
where s.country in ('')
It works with the prompt macro but dosent work with promptmany.
Any suggestions?

Use Static choices. For one option, Display 'All' and use 'All'.
In your filter:
case ?prompt1?
when 'All' then ( 1 = 1 )
else ( [do something here] )
end

After trying a lot of options, I was able to manipulate the SQL. The below SQL works
and ( #prompt('IJParam', 'string', '1=1' , 's.ij_code=')#
or
#promptmany('IJParam', 'string', ' 1=1' , ' s.ij_code in (', 'IJParam', ' )')#
)

Related

How can I insert text in ANY empty field of a layout in filemaker?

I would like to write a script which goes to the first field of my layout, then evaluate if it is empty or not; if yes, it inserts "n.s." [not specified] and if it is not empty, it goes to the next field. And so on until the last field of my layout. In the end, it makes either a beep or a window appears saying "all done" (but this last part is optional and I can already do it).
My goal is to have a button which activates this script only when I press on it.
Up until now, I could make my script go from one field to another, but it would not write anything in the empty field it met... Aditionnally, most of the written function need a named target field and I would like to be able to go automatically from one field to another without having to change the target field name myself.
Here is my script at the moment:
Go to Field [Select/perform; Layout#1::Field#1]
If [IsEmpty ( Get ( ActiveFieldName ) )]
Insert Text [Select; "n.s."]
Go to Next Field
End If
Beep
It beeps but it doesn't write anything...
Or do you see a better solution ?
Not sure why you would need this, but if necessary, you could do it this way:
Go to Next Field
Set Variable [ $start; Value:Get ( ActiveFieldName ) ]
Loop
If [ IsEmpty ( Get ( ActiveFieldContents ) ) ]
Insert Text [ “n.s.” ]
End If
Go to Next Field
Exit Loop If [ Get ( ActiveFieldName ) = $start ]
End Loop
Beep
Note that this is (purposefully) not committing the record. And of course, all fields on the layout (or at least the fields that you want to include in this process) must be included in the tab order.

How to Correct the error in this SQL script (Database Using Azure Datawarehouse)

I am having a hard time when I try to run the script below. Error messsage:
Order by clause not valid in views and inline functions
insert into cc.s
(
id,
encid,
a_name,
a_des,
a_type,
a_value,
d_create
)
select
id,
encid,
'days_charge',
'Days 43',
'int',
(
select
datediff(day,t_dis,a.ts_it)
from
cc.enoun
where
encid <> a.encid
and id=a.pe_id
and a_source='tEst'
and a.ts_admit > t_dis
order by
tdischarge desc limit 1
) as attr_value,
getdate()
from
cc.s a
GO
In your script, you're trying to use a SELECT statement to get the a_value. Your problem here is that this select statement is your inline function. Since an inline function can't have an ORDER BY clause, you simply have to remove it.
insert into cc.s(id, encid, a_name, a_des, a_type, a_value, d_create)
select id, encid,'days_charge','Days 43','int',
(select datediff(day,t_dis,a.ts_it) from cc.enoun where encid<>a.encid and id=a.pe_id and a_source='tEst' and a.ts_admit>t_dis)
as attr_value,
getdate()
from cc.s a
GO
Also make sure that your inline statement returns only 1 value. Since you were trying to use an ORDER BY clause, that may mean that it returns multiple results.

Condition IF In Power Query's Advanced Editor

I have a field named field, and I would like to see if it is null, but I get an error in the query, my code is this:
let
Condition= Excel.CurrentWorkbook(){[Name="test_table"]}[Content],
field= Condition{0}[fieldColumn],
query1="select * from students",
if field <> null then query1=query1 & " where id = '"& field &"',
exec= Oracle.Database("TESTING",[Query=query1])
in
exec
but I get an error in the condition, do you identify the mistake?
I got Expression.SyntaxError: Token Identifier expected.
You need to assign the if line to a variable. Each M line needs to start with an assignment:
let
Condition= Excel.CurrentWorkbook(){[Name="test_table"]}[Content],
field= Condition{0}[fieldColumn],
query1="select * from students",
query2 = if field <> null then query1 & " some stuff" else " some other stuff",
exec= Oracle.Database("TESTING",[Query=query2])
in
exec
In query2 you can build the select statement. I simplified it, because you also have conflicts with the double quotes.
I think you're looking for:
if Not IsNull(field) then ....
Some data types you may have to check using IsEmpty() or 'field is Not Nothing' too. Depending on the datatype and what you are using.
To troubleshoot, it's best to try to set a breakpoint and locate where the error is happening and watch the variable to prevent against that specific value.
To meet this requirement, I would build a fresh Query using the PQ UI to select the students table/view from Oracle, and then use the UI to Filter the [id] column on any value.
Then in the advanced editor I would edit the generated FilteredRows line using code from your Condition + field steps, e.g.
FilteredRows = Table.SelectRows(TESTING_students, each [id] = Excel.CurrentWorkbook(){[Name="test_table"]}{0}[fieldColumn])
This is a minor change from a generated script, rather than trying to write the whole thing from scratch.

IBM Cognos prompt value when not entered

I have a problem in report studio. please help me to figure this out..
i have a optional prompt, i want to check whether the value is selected or not..
Please help how to check..
if (?parameter? is null ) then ('1') else ('2')
or
if (ParamDisplayValue('parameter') is null ) then ('1') else ('2')
Both the above are not working..
Suppose if i select any value in the prompt then the else part works and i get the result as 2, if i wont select anything then i'm not getting the result as 1
My guess, without doing extensive testing, is that an empty optional prompt doesn't exist at all and can't be compared to null. That said, I believe there's an easy fix.
Since you know that when you select an item '?parameter? is null' will return false, '?parameter? is not null' should return true and you can reverse the logic:
if (?parameter? is not null) then ('2') else ('1')
Try to put a conditional block. Set a block variable of type boolean with this expression:
ParamDisplayValue('myParam') is null
Then go to your conditional block again switch property "current block" to yes/no.
When yes (meaning that our block variable is true so the parameter is null) add a text item and just write "All".
When no add a text item with source type as report expression and write ParamDisplayValue('myParam')
P.S: there is also a way to count how many values the user selected (so as not to display all of them 1 by 1 but just show "62 values selected") but it needs some javascript and a hidden prompt field.
Use ParamCount
More details here:
http://joesanswers.blogspot.com.au/2008/09/checking-for-empty-parameters-in-cognos.html

Using SELECT .. AS in a Python Sqlite query

In SQLite3, I have a "Accounts" table. I can run any of these queries:
SELECT Last_Bal AS Balance FROM Accounts;
SELECT Last_Bal AS 'Balance' FROM Accounts;
SELECT Last_Bal as "Balance" FROM Accounts;
All three queries run fine, and display the word "Balance" as the column heading.
However, when I run this code in Python 3:
c.Execute( 'SELECT Last_Bal AS Balance FROM Accounts' )
I get the error message: "sqlite3.OperationalError: near "Balance": syntax error". If I try putting single quotes or double quotes around the word Balance, as in this:
c.Execute( 'SELECT Last_Bal AS "Balance" FROM Accounts' )
I get the error message: "_tkinter.TclError: Invalid column index Balance"
I've tried swapping the single quotes for double quotes, and even triple quotes, but nothing seems to work.
SOLVED: Stupid User Error - I was using two different SELECT statements trying to build a TreeView. Thanks for your help.

Resources