Parameter for SQL

Tom
New Contributor II

When I have a BR, and need to pull in a parameter, I use the following statement or one similar, I create the parameter in a Dashboard.

'Dim scenario As String = BRApi.Dashboards.Parameters.GetLiteralParameterValue(si, False, "Forecast_Scenario")

How do you bring a parameter into SQL ?  I tried the above and it doesn't work.  I would like to set a parameter such as date, and then bring the parameter inside SQL, the same way I do as a BR.

Thanks for your help in advance.

Tom

1 ACCEPTED SOLUTION

Krishna
Valued Contributor

@Tom  -    Assume the below is the parameter in the BR

Dim Date As String = BRApi.Dashboards.Parameters.GetLiteralParameterValue(si, False, ParamName)
In the SQL You will be calling the String
WHERE SQL COL NAME = '" & Date & "'"

The ParamName is created in the Dashboard Parameter.

Hope this helps!

Thanks
Krishna

View solution in original post

8 REPLIES 8

Krishna
Valued Contributor

@Tom - See below in Parameters This is a connector rule example. WHen you are calling SQL inside the BR.

' Dim wfYear As String = periodName.Substring(0,4)
' Dim wfMonth As String = periodName.Substring(5)
'Where Clause
whereClause.Append("WHERE YEAR = '" & wfYear & "'")
whereClause.Append("AND PERIOD ='" & wfMonth & "'" )
Thanks
Krishna

Tom
New Contributor II

Thanks Krisna,

I was thinking of creating a parameter like "As of Date", and not a workflow parameter, and then bringing in my parameter into the SQL, right now SQL does not recognize the Parameter.

Krishna
Valued Contributor

@Tom  - As of Date is a column in your DB ? then you are trying to pass the param in SQL, if so Did you try calling it Data Adapter first? to see it is working. Then you can hardcode the value in BR.

In my Previous response it is just an example of how you can Call the parameters. 

Thanks
Krishna

Tom
New Contributor II

I currently have the value hardcoded in the SQL, but wanted to create a parameter if possible.  Thanks for your help, I really appreciate it.

Krishna
Valued Contributor

@Tom  -    Assume the below is the parameter in the BR

Dim Date As String = BRApi.Dashboards.Parameters.GetLiteralParameterValue(si, False, ParamName)
In the SQL You will be calling the String
WHERE SQL COL NAME = '" & Date & "'"

The ParamName is created in the Dashboard Parameter.

Hope this helps!

Thanks
Krishna

Tom
New Contributor II

Krishna,

it worked, I don't understand the syntax 

'" & Date & "'

Thanks so much for your help, I really appreciate it.

Tom 

ThorJensen
New Contributor II

@Tom Assuming that your SQL is running inside a data adaptor, and as such here is not related to any BR. 

You can simply call a parameter in SQL by referencing it with pipes. I've used used this kind of where clause in the past:

WHERE Source.columnname <= '|!SelectedPeriodEnd_TXM!|')

Here |!SelectedPeriodEnd_TXM!| is my parameter.

Hope this might help. 

Best Thor

 

Henning
Valued Contributor

Hi, please read this blog entry and the comments for more information on this.

SELECT Like a Boss With Query Parameters - OneStream Community (onestreamsoftware.com)

Using Query Parameters is highly recommended! 🙂