Page 1 of 2

Add condition to the query sql before the execution

Posted: Thu Mar 16, 2017 4:58 pm
by r.bianco
In web designer, how can I add a condition to the query sql before the execution? This condition should not be viewed or modified by the user, but the Query Text in the Editor must be editable.

Re: Add condition to the query sql before the execution

Posted: Fri Mar 17, 2017 6:54 am
by HighAley
Hello.

Unfortunately, there are no Conditions for the SQL query.
Could you describe your scenario more detailed, maybe we can't suggest you something else?

Thank you.

Re: Add condition to the query sql before the execution

Posted: Fri Mar 17, 2017 8:15 am
by r.bianco
Good morning.
Scenario: Consider a single report. The application processes the main print data and populating a special table. All processing / prints populate the same table. To distinguish a processing / printing on the other we use a UID field.
The report must extract the filtering data by UID.
By the designer, the user can add more data, but it does not remove the filter by UID.
In other words, can I add a string to all queries of the reports before they are executed?
Thank you.

Re: Add condition to the query sql before the execution

Posted: Fri Mar 17, 2017 2:20 pm
by Alex K.
Hello,

As a way, you can try to use the variable in the query as you needed:
select * from table {Variable1}

and in Variable1 provide necessary where conditions or additional columns.

Thank you.

Re: Add condition to the query sql before the execution

Posted: Tue Mar 21, 2017 1:43 pm
by r.bianco
Yes, but, through Web Designer, the user can delete the variable from the query.
I would rather that the user can modify the query without removing this condition.
Thank you.

Re: Add condition to the query sql before the execution

Posted: Wed Mar 22, 2017 9:17 pm
by Alex K.
Hello,

You can check it in your code and modify query if the necessary:
((StiSqlSource)report.Dictionary.DataSources[ "DataSourceName"]).SqlCommand = newSqlCommand;

Thank you.

Re: Add condition to the query sql before the execution

Posted: Thu Mar 23, 2017 9:17 am
by r.bianco
OK thanks.
In what event?
OnGetDataBinding
OnGetReportData
OnInit
onload
OnReportConnect
?
another?

Re: Add condition to the query sql before the execution

Posted: Fri Mar 24, 2017 1:10 pm
by Alex K.
Hello,

Please try to use it in OnGetReportData.

Thank you.

Re: Add condition to the query sql before the execution

Posted: Wed Mar 29, 2017 10:24 am
by r.bianco
Very well, thank you!
There is a further problem: I would like to apply the same in the Web Designer, on the View Data function
Immagine.png
Immagine.png (88.63 KiB) Viewed 5316 times
and on the Preview.
I tried the same code in OnPreviewReport and OnDataBinding, but runs only the second time I run the preview. What is the right event?
Thank you.

Re: Add condition to the query sql before the execution

Posted: Fri Mar 31, 2017 7:26 am
by Alex K.
Hello,

Unfortunately, at the current moment, there are not any events for this action. Sorry.

Thank you.