passing parameters in ado.net source - ssis

I wanted to pass a parameterized query in ado.net source and i rea don this post that only way to do this is to use expressions.
So here is my expression
"SELECT
LEDGER_YR_MO,
LOCATION,
FDR_FND_NO,
FDR_INVST_POOL_CD,
FISCAL_YR_BEG,
FISCAL_YR_END,
POST_DATE,
FDR_FND_TTL,
FDR_FND_TYPE_CD,
FDR_FND_PURP_CD,
FDR_CR_ELIG_FL,
FDR_ANN_CR_RATE,
FDR_MTH_CR_RATE,
FDR_CR_AMT,
FDR_TR_ELIG_FL,
FDR_ANN_TR_RATE,
FDR_MTH_TR_RATE,
FDR_60MTH_AVG_SHARE_PRC,
FDR_TR_AMT,
FDR_PROJ_GEP_INCM_AMT,
FDR_TR_AUGMENTATION_AMT,
FDR_GEP_NET_PAYOUT_AMT
FROM
FS0TST.UCOP_FDR_TR_CR where
LEDGER_YR_MO = '"+ (DT_WSTR,30) #[User::END_LEDGER_YR] +"' "
but when I click evaluate the expression , I see blank instead of variable ..does anyone know the possible issue:
Here is the evaluate expression looks like
SELECT
LEDGER_YR_MO,
LOCATION,
FDR_FND_NO,
FDR_INVST_POOL_CD,
FISCAL_YR_BEG,
FISCAL_YR_END,
POST_DATE,
FDR_FND_TTL,
FDR_FND_TYPE_CD,
FDR_FND_PURP_CD,
FDR_CR_ELIG_FL,
FDR_ANN_CR_RATE,
FDR_MTH_CR_RATE,
FDR_CR_AMT,
FDR_TR_ELIG_FL,
FDR_ANN_TR_RATE,
FDR_MTH_TR_RATE,
FDR_60MTH_AVG_SHARE_PRC,
FDR_TR_AMT,
FDR_PROJ_GEP_INCM_AMT,
FDR_TR_AUGMENTATION_AMT,
FDR_GEP_NET_PAYOUT_AMT
FROM
FS0TST.UCOP_FDR_TR_CR where
LEDGER_YR_MO = ''

When you click the Evaluate Expression button, no code actually gets executed, so the only thing SSIS can look at is the static default value you gave your variable.
If you want to see a value instead of a blank in the Evaluate Expression, you have to give your variable a default value, even if you don't intend to use that value. When the SSIS package is executed, whatever code you use to populate the variable will overwrite the default value, so having a default value is harmless.

Related

Index was outside the bounds of the array in SSRS

I have two parameters , let's say P1 and P2. The sample expression I used for P2 is
IIF(P1.Label="string", "null" ,Split(P1.Label," ").GetValue(0))
When the condition is false, the split expression is working fine. But if the condition is true, I'm getting 'Index was outside the bounds of the array' error. If the condition is true, I need to pass the value "null" as varchar type.
Can someone please advice on this?
The problem with the IIF function is that it is a function not a language construct. This means that it evaluates both parameters before passing the parameters to the function. Consequently, if you are trying to do a Split on a parameter that can't be split, you will still get the 'Index was outside the bounds of the array' error, even when it looks like that code shouldn't be executed due to boolean condition of the IIF statement.
The best way to solve this is to create a safe string splitter function in custom code where you can use real language constructs. Also, check that the string is splittable by checking it contains a space instead of checking for a special string:
Public Function SafeSplit(ByVal SplitThis As String) As String
If InStr(SplitThis, " ") Then
Return Split(SplitThis, " ")(0)
End If
Return "null"
End Function
and then use this in your report for the Value expression instead of IIF:
=Code.SafeSplit(Parameters!P1.Label)

Parameter filter SSRS Expression Dataset

I have a dataset created from an expression that takes parameters from 3 other datasets.
I need to add a parameter to this that allows the user to input a value, and then the dataset will add that value to the where clause to filter the results displayed. If the value "Any" is input then the results will be unfiltered for this section of the Where clause (If that makes sense).
I wrote this and added it to the expression Where clause, but it is not working.
+ IIf(Parameters!RCode.Value = "ANY", "", " AND h.rcode = " + Parameters!RCode.Value + " ")
I can provide the rest of the where clause if it is needed, but if i remove this line, the whole thing works, if i add this line, it bombs out with
An error has occurred during report processing. (rsProcessingAborted)
Cannot set the command text for dataset 'DS'. (rsErrorSettingCommandText)
In the dataset query you can use parameter names by simple prefixing them with # eg. #RCode
To make it work, your WHERE clause should be look like (I assume your column name is rcode):
WHERE ....
AND (#RCode = 'ANY' OR rcode = #RCode )
For multivalue parameters
WHERE ...
AND ('ANY' IN (#RCode) OR rcode IN (#RCode) )

Issue in where condition while using in mdx

I have parameter value: 'Paris carlton' when 'm trying to pass this value in mdx as (StrTomember(#Parameter)) i'm getting error.
How to pass the total name 'Paris Carlton' in where condtn. to filter the parameter value.
when i tried:when pass this parameter value, it is considering only Paris and not Carlton thus resulting in error. how to consider the full name while passing a value in mdx?
If you are doing this :
(StrTomember(#Parameter))
Then #Parameter will need to be a string that represents the full member name. So you can either do an expression in SSRS to create a string that looks like this:
"[Geo Dimension].[Country hierarchy].&[Paris Carlton]"
Or you could build it inside the strToMember function:
(StrTomember("[Geo Dimension].[Country hierarchy].&[" + #Parameter +"]"))

SpagoBI OLAP report passing optional parameter

Helo. Today is my another fight day with OLAP raport with optional parameter. I have problem with MDX query. I wrote it like this:
select
NON EMPTY {{[Measures].[VALUE]}} ON COLUMNS,
NON EMPTY {
IIF(ISEMPTY([CUSTOMER].[${param}]) //CHECKING IF PARAMETER IS EMPTY
,{[CUSTOMER].[COUNTRY].Members},
{[CUSTOMER].[${param}]}
)
}ON ROWS
from [TRANSACTIONS]
${param} is my optional parameter for [CUSTOMER].[COUNTRY]. I unchecked "required" check button for my parameter, so OLAP should have all [VALUE] after executing it without parameter. And there is a problem, because after launching my OLAP raport parameter probably wants to be filled with something. It gives me an error.
Profile attribute 'param' not existing.
But I dont want to fill it with profile attribute. I have created list of values, and analytical driver for my parameter, which I use to pass possible values to my list box string parameter - ${param}.
Is there possibility to have OLAP report with optional parameter? Any BI master here?
I would be greatfull for any help.
Update: I have done something like this, I think this syntax is right, (I was checking SpagoBI examples)
WITH MEMBER [CUSTOMER].[SELECTED] AS ' Parameter("param") ' , SOLVE_ORDER = 2
MEMBER [CUSTOMER].[LEN] AS ' LEN(Parameter("param")) ', SOLVE_ORDER = 1
select
NON EMPTY {{[Measures].[VALUE]}} ON COLUMNS,
NON EMPTY {
IIF([CUSTOMER].[LEN]=0
,{[CUSTOMER].[COUNTRY].Members},
{[CUSTOMER].[CUSTOMER].[SELECTED]}
)
}ON ROWS
from [TRANSACTIONS]
But now I have same error for both possibilities (set/unset) parameter
javax.servlet.jsp.JspException: org.apache.jasper.JasperException: javax.servlet.ServletException: javax.servlet.jsp.JspException: com.tonbeller.jpivot.olap.model.OlapException: 1
Any ideas? Thanks :)
This question is a direct copy oF your previous posts:
https://stackoverflow.com/questions/38970610/olap-report-with-optional-parameter
Is ${param} is a string?
If it is a string then the following should function:
WITH MEMBER [Measures].[x] AS ${param}
SELECT
NON EMPTY {[Measures].[x]} ON COLUMNS
FROM [TRANSACTIONS];
Does it function?
If it does not function then the question is not really mdx related - as for some reason your syntax or the way the parameter is moving to the client is wrong.
note
The above is the equivalent of this super simple script:
WITH
MEMBER [Measures].[x] AS "hello world"
SELECT
NON EMPTY
{[Measures].[x]} ON 0
FROM [Adventure Works];
Do you have AdvWrks cube? Try these:
WITH
MEMBER [Measures].[x] AS "I'm not empty"
SELECT
{
IIF
(
(IsEmpty([Measures].[x])) //<< this returns False
,[Product].[Product Categories].[Category].MEMBERS
,{[Measures].[x]} //<< this is what IIF returns
)
} ON 0
FROM [Adventure Works];
It returns this:
Now I tested out IsEmpty:
WITH
MEMBER [Measures].[x] AS "I'm not empty"
SELECT
{
IIF
(
(NOT //<< added this to check functionality of IsEmpty
IsEmpty([Measures].[x]))
,[Product].[Product Categories].[Category].MEMBERS //<< this is what IIF returns
,{[Measures].[x]}
)
} ON 0
FROM [Adventure Works];
We get the following:
What I think is happening in your scenario is this - the param is not empty but is actually a zero length string:
WITH
MEMBER [Measures].[x] AS ""
SELECT
{
IIF
(
(
IsEmpty([Measures].[x]))
,[Product].[Product Categories].[Category].MEMBERS
,{[Measures].[x]} //<< the zero length string goes to here
)
} ON 0
FROM [Adventure Works];
Results in:

conditional filter SSRS

My situation is
I have a parameter, this is a list, allowing multi values. That mean the first record in the list is 'Select All'
When user select All I need to include in my report all records that match with the list plus those that are blank. (My dataset is returning these)
When user select only 1 or a few I want to include only these records. No those that are blank
My problem:
I have a filter in my dataset that evaluate a parameter in a list, but I need to add a conditional filter to include a blank records when the selection will be "Select All"
I tried to use expression but this doesn't work
Filter expression
Fields!NAME.Value in = Parameters!List.Value !!!!!!!!!!!! Work Fine
But I need to change it like as
If Parameters!List.Value = 'Select All' Then
Fields!NAME.Value in = Parameters!List.Value or Fields!NAME.Value = " "
Else
Fields!NAME.Value in = Parameters!List.Value
End
Can you give an advice who can I resolve it please !!!
I'm working in SSRS R2
Thanks!!
This worked for me
Expression: =IIF(Parameters!pLocation.Value <> " All Locations", Fields!LOCATION.Value, FALSE)
Operator: =
Value: =IIF(Parameters!pLocation.Value <> " All Locations", Parameters!pLocation.Value, FALSE)
If you use Filter on your Dataset, try this:
Expression: [NAME]
Operator: IN
Value (fx): =Split(Replace(Join(Parameters!List.Value, ","), "Select All", " "), ",")
Try to work along this path. Basically you can reconstruct the multi value items into a string with Join(), and deconstruct it again into array by using Split(); where in between, you can manipulate them, for modifying (e.g. converting "Select All" into " "), adding (imitating "OR"), or removing extra items.
There is an alternative for this.
Add one more item to the paramater dataset values say "Not Available" as Label and value with the null. then there will be no change in the stored procedure and you can retrieve the data.
If the user select the specific item then he will get those values only. If he selects all then he will get the data for the null also with the all the others.
Hope this will help
You can put the logic in just one location if you do it this way.
You filter on the parameter, unless it's all values then the filter always matches.
Just a little cleaner.
Expression: =IIF(Parameters!pLocation.Value <> " All Locations", Fields!LOCATION.Value, " All Locations")
Operator: =
Value: =Parameters!pLocation.Value