Add condition to the query sql before the execution

Stimulsoft Reports.WEB discussion
r.bianco
Posts: 81
Joined: Thu Oct 27, 2016 2:06 pm

Add condition to the query sql before the execution

Post 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.
Soft System srl
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Add condition to the query sql before the execution

Post 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.
r.bianco
Posts: 81
Joined: Thu Oct 27, 2016 2:06 pm

Re: Add condition to the query sql before the execution

Post 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.
Soft System srl
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: Add condition to the query sql before the execution

Post 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.
r.bianco
Posts: 81
Joined: Thu Oct 27, 2016 2:06 pm

Re: Add condition to the query sql before the execution

Post 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.
Soft System srl
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: Add condition to the query sql before the execution

Post 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.
r.bianco
Posts: 81
Joined: Thu Oct 27, 2016 2:06 pm

Re: Add condition to the query sql before the execution

Post by r.bianco »

OK thanks.
In what event?
OnGetDataBinding
OnGetReportData
OnInit
onload
OnReportConnect
?
another?
Soft System srl
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: Add condition to the query sql before the execution

Post by Alex K. »

Hello,

Please try to use it in OnGetReportData.

Thank you.
r.bianco
Posts: 81
Joined: Thu Oct 27, 2016 2:06 pm

Re: Add condition to the query sql before the execution

Post 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 5323 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.
Soft System srl
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: Add condition to the query sql before the execution

Post by Alex K. »

Hello,

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

Thank you.
Post Reply