If you are unable to create a new account, please email support@bspsoftware.com

 

return value of ParamValue / ParamDisplayValue always in text format?

Started by MrKlar, 08 Oct 2024 04:13:18 AM

Previous topic - Next topic

MrKlar

Dear Cognos-fellows,

I wonder wether a parameter value, retrieved by either ParamValue('paramter_name') or ParamDisplayValue('paramter_name'), is always in text format?

In my example I set the "parameter use value" to a numeric field in the database. However, if I want to do numeric calculations with that "use value" in a layout calculation, I get an error ("The operand types [...] are not compatible."). I do not get the error if I to convert the value to a number at first.

Thank you for your answers.

MFGF

Quote from: MrKlar on 08 Oct 2024 04:13:18 AMDear Cognos-fellows,

I wonder wether a parameter value, retrieved by either ParamValue('paramter_name') or ParamDisplayValue('paramter_name'), is always in text format?

In my example I set the "parameter use value" to a numeric field in the database. However, if I want to do numeric calculations with that "use value" in a layout calculation, I get an error ("The operand types [...] are not compatible."). I do not get the error if I to convert the value to a number at first.

Thank you for your answers.

I believe ParamValue() and ParamDisplayValue() will always return character strings. They are for use in layout calculations, rather than query calculations.

I'm assuming you're trying to reference the value for use in a query calculation? Have you tried simply referring to the parameter in your expression by name (eg ?parameter_name? )?

Cheers!

MF.
Meep!

dougp

In the Report expression dialog, there are tabs along the bottom, below Available Components.  Looking at the Functions tab, I see a function named string2int32().  Maybe give that a go.

cognostechie

Quote from: MrKlar on 08 Oct 2024 04:13:18 AMDear Cognos-fellows,

I wonder wether a parameter value, retrieved by either ParamValue('paramter_name') or ParamDisplayValue('paramter_name'), is always in text format?

In my example I set the "parameter use value" to a numeric field in the database. However, if I want to do numeric calculations with that "use value" in a layout calculation, I get an error ("The operand types [...] are not compatible.").
Quote from: MrKlar on 08 Oct 2024 04:13:18 AMDear Cognos-fellows,

I wonder wether a parameter value, retrieved by either ParamValue('paramter_name') or ParamDisplayValue('paramter_name'), is always in text format?

In my example I set the "parameter use value" to a numeric field in the database. However, if I want to do numeric calculations with that "use value" in a layout calculation, I get an error ("The operand types [...] are not compatible."). I do not get the error if I to convert the value to a number at first.

Thank you for your answers.

Thank you for your answers.

You said that the value is already numeric in your database so which value did you convert to a number?

I am not sure if Layout calculation will allow functions but query calculation does allow that.

cast( ?parameter_name?, int) OR  cast( ?parameter_name?, char)

If you DB is SQL Server then thus might also work

cast( ?parameter_name? as integer) OR  cast( ?parameter_name? as char)

MrKlar

Quote from: dougp on 08 Oct 2024 06:09:45 PMIn the Report expression dialog, there are tabs along the bottom, below Available Components.  Looking at the Functions tab, I see a function named string2int32().  Maybe give that a go.

I also found the function string2int32() in the layout calculation, that you are referring to. It works, thanks for the hint.

Quote from: cognostechie on 08 Oct 2024 07:08:19 PMYou said that the value is already numeric in your database so which value did you convert to a number?
The value in the database is numeric. I fill the prompts creating the parameter that I want to display in the layout calculation with these numeric values. Nonetheless, ParamValue() and ParamDisplayValue() seem to always return the values in text format. Which is fine with me since I can use the function mentioned above.