1 (edited by geochrist 2022-10-04 06:55:48)

Topic: How to pass variables to sql report queries

Hi to all,

I have a grid that displays the data from an attached database.
On the same form that the grid resides I also have some drop down boxes to select values to build queries on the displayed data. Everything works of and the data are filtered and displayed on the grid based on the drop down selections.

Now this is the problem that I have:

I wish to create a report on the displayed data (which belong to an attached database).
I have build a button that is setup as an SQL report.
How do I setup the sql query so that I can pass variable data to it and get results from an attached database?

for example: I have a variable names 'make' where I store the name of the make of the car that I want to get data for from the attached table.
The attached table has a name 'products' and the attached database has a name of 'Test'.

How would the sql query be setup?

for example :  SELECT * FROM "PRODUCTS" WHERE "Feature:Μάρκα"= '+make+'  ORDER BY "Feature:ΕίδοςΑνταλλακτικού" AND "Feature:Θέσηανταλλακτικού"

What am I doing wrong?

Thank you

Post's attachments

Attachment icon mvd.png 12.08 kb, 85 downloads since 2022-10-04 

Re: How to pass variables to sql report queries

Hi,


Create a hidden TextBox on the form in which to display the 'make' variable.
The SQL query will look like:
SELECT * FROM "PRODUCTS" WHERE "Feature:Μάρκα"= {TextBoxName} ORDER BY "Feature:ΕίδοςΑνταλλακτικού" AND "Feature:Θέσηανταλλακτικού"


http://myvisualdatabase.com/help_en/SQLquery.html

Re: How to pass variables to sql report queries

Thank you so much for your help. I will try it out.

Re: How to pass variables to sql report queries

Yes it works this way.

Thank you very much

Regards
George

Re: How to pass variables to sql report queries

With this solution, there is no need to write the query yourself. You can specify a table and a field for a TextBox and use the standard function Report with a search for this TextBox