Topic: SQLQuery for select in the Grid

Hello, I do not speak much English, so I will try to formulate my question in the best possible way.

How can I make several selections in the "Table Grid" object and print them through a SLQQuery?

I print one with this code

SELECT
   
student.firstname,
student.lastname,
student.photo,
student.direcpart,
student.datoscadete,
student.parentname,
student.material,
student.yearstart,
student.yearend,
student.ujc,
student.cdr,
student.pcc,
student.fmc,
groupname.groupname,
sex.sexname,
prohod.proname,
munihod.muniname,
socialstatus.socialstatus,
university.nuniversity,
specname.specname,
student.surname,
student.phone,
student.ci,
student.id

FROM student

LEFT OUTER JOIN groupname ON student.id_groupname = groupname.id
LEFT OUTER JOIN sex ON student.id_sex = sex.id
LEFT OUTER JOIN prohod ON student.id_prohod = prohod.id
LEFT OUTER JOIN munihod ON student.id_munihod = munihod.id
LEFT OUTER JOIN university ON student.id_university = universidad.id
LEFT OUTER JOIN specname ON student.id_specname = specname.id
LEFT OUTER JOIN socialstatus ON student.id_socialstatus = socialstatus.id
WHERE student.id = $ id

if I want to print all I remove the last line.

But, how a selection?

Re: SQLQuery for select in the Grid

Pleaseeeeeeee, Helppppppp!!!!!

Re: SQLQuery for select in the Grid

Hello.


Why you use SQL query for the report?


You can do it without using SQL,


1. Just set up button with action "Report"
2. In the first list of setting the button "1. Select the components involved in the search" add component TableGrid
3. Use Object Inspector change the property of TableGrid: Additional > Options > goMultiselect = True
4. Now you can select severals records in the TableGrid using Ctrl button and print them.

Dmitry.

4 (edited by mathmathou 2017-11-22 10:20:23)

Re: SQLQuery for select in the Grid

Hello wenchester21,


I think Dmitry is correct, his solutionis the simplest you can apply.


But you could have to use script for other reasons than printing.
In that case, you can use the property of your Tablegrid to achieve that.

Let's say you have a Tablegrid1 on Form1 and the user selected some products in it. In order to get the ID of these selected products, you could do something like :

procedure Form1_Button1_OnClick (Sender: string; var Cancel: boolean);
var
    i : Integer;
    product_id : Integer;
begin
    for i := 0 to Form1.TableGrid1.RowCount - 1 do
        begin
            if Form1.TableGrid1.Selected[i] then //if the row is selected
                begin
                    product_id := Form1.TableGrid1.dbIndexToID(i); //convert the row number to database ID
                    ShowMessage(IntToStr(product_id));
                end;
        end;
end;

Of course, this would give you a series of popups with the id number in it which is of no real use, but you get the general idea.


If you need help to insert them in a temporary table of in a stringlist or array, just say so and I'll provide an example.


Hope this helps


Cheers


Mathias

I'm a very good housekeeper !
Each time I get a divorce, I keep the house

Zaza Gabor

5 (edited by wenchester21 2017-11-22 16:06:43)

Re: SQLQuery for select in the Grid

DriveSoft wrote:

Hello.


Why you use SQL query for the report?


You can do it without using SQL,


1. Just set up button with action "Report"
2. In the first list of setting the button "1. Select the components involved in the search" add component TableGrid
3. Use Object Inspector change the property of TableGrid: Additional > Options > goMultiselect = True
4. Now you can select severals records in the TableGrid using Ctrl button and print them.

Hi.

I used the way you told me and I get this error.

Post's attachments

Attachment icon error.png 46.91 kb, 126 downloads since 2017-11-22 

Re: SQLQuery for select in the Grid

Discard that there is a lack of data in the DB, since I have several records entered and using the SQL query works well, but not with multi-selection.

This is the action window

Post's attachments

Attachment icon action.png 68.79 kb, 128 downloads since 2017-11-22 

Re: SQLQuery for select in the Grid

mathmathou wrote:

Hello wenchester21,

I think Dmitry is correct, his solutionis the simplest you can apply.
...

Hello mathmathou.

Yes, I take the idea and it is very useful to solve another problem I have. It's very similar to what you mentioned earlier. If you could upload an example of what I ask (print multiselection in a report) and another with the case insert them in a temporary table of in a stringlist or array, it would be very helpful.

Thanks for the help

Re: SQLQuery for select in the Grid

wenchester21 wrote:

Discard that there is a lack of data in the DB, since I have several records entered and using the SQL query works well, but not with multi-selection.

This is the action window

please attach your project.

Dmitry.

Re: SQLQuery for select in the Grid

DriveSoft wrote:
wenchester21 wrote:

Discard that there is a lack of data in the DB, since I have several records entered and using the SQL query works well, but not with multi-selection.

This is the action window

please attach your project.

This is a small example of what happens. When you open it, you will see that there are 3 buttons to print. The one in bold is the one that gives the error.

Post's attachments

Attachment icon small_proyect.rar 294.94 kb, 311 downloads since 2017-11-22 

Re: SQLQuery for select in the Grid

Beginning from version 3.4 in the reports, the names of the fields contain the names of the table. I just fixed report template and SQL query. Check it out:

Post's attachments

Attachment icon small_proyect_fixed.zip 6.7 kb, 281 downloads since 2017-11-22 

Dmitry.

11 (edited by wenchester21 2017-11-23 14:53:37)

Re: SQLQuery for select in the Grid

DriveSoft wrote:

Beginning from version 3.4 in the reports, the names of the fields contain the names of the table. I just fixed report template and SQL query. Check it out:

I've already seen where the error is. Thanks .., now another question.

To obtain the data of a field in a Memo, I mean like this:

[Report. "sex.sexname"]

Now, to objener the value of a chekbox ???

I do it in the "DataField" property, I simply put the name of the data.
What now with what you told me do not know how to do it below I put ideas, is any one right?

sex.ujc

or

ujc

This last one worked for me when I did it for SQLReport.

Re: SQLQuery for select in the Grid

This is the error that I get when I click on the button.

Post's attachments

Attachment icon print error.jpg 32.37 kb, 121 downloads since 2017-11-24 

Re: SQLQuery for select in the Grid

Please attach your project.

Dmitry.

Re: SQLQuery for select in the Grid

DriveSoft wrote:

Please attach your project.

Hi, can you give me an email where to send it?

Re: SQLQuery for select in the Grid

wenchester21 wrote:
DriveSoft wrote:

Please attach your project.

Hi, can you give me an email where to send it?

support@drive-software.com
in the letter, specify the link to this topic.

Dmitry.