Topic: Need help!About Tablegrid

Hi,there are some records like this
Name    Year      Performance
Jack            2019    A
Jack            2020        A
Jack            2021    B
Judy    2019    C
Judy    2020    B
Judy    2021    B
San            2019    A
San        2020    B
San            2021    C
I want to list these records in the tablegrid like this,how can i do it?
Name    2019    2020    2021
Jack              A               A           B
Judy      C               B            B
San              A               B            C

2 (edited by sparrow 2022-01-03 13:50:47)

Re: Need help!About Tablegrid

Hi,
look  example from script or from report

Post's attachments

Attachment icon my-2exampl.zip 335.85 kb, 219 downloads since 2022-01-03 

Re: Need help!About Tablegrid

Thanks much! It works well.
Another question:the year is variable,how can i do ?thaks.

Re: Need help!About Tablegrid

What do you mean ?
Can you be more specific?

5 (edited by sparrow 2022-01-03 16:19:13)

Re: Need help!About Tablegrid

Perhaps you talked about it.
The request is generated dynamically based on the number of returned values.

Post's attachments

Attachment icon my-dyn sql.zip 336.85 kb, 254 downloads since 2022-01-03 

Re: Need help!About Tablegrid

Hi Sparrow,
Great solution and very useful for future reference.
Thanks.
D.

Re: Need help!About Tablegrid

Hi Derek,
Thanks.

Re: Need help!About Tablegrid

sparrow wrote:

Perhaps you talked about it.
The request is generated dynamically based on the number of returned values.

Thank for your warmly help.I am sorry I didn't tell my proposal clearly.
The attachment is my proposal.I haven't study the programm about Object Pascal ,SQL,but I think the MVD is  correct for me do the project.
Then ,can you give me some advice ? Is there any course for beginner for Pascal,SQL?

Post's attachments

Attachment icon About My Project.docx 61.86 kb, 209 downloads since 2022-01-04 

9 (edited by sparrow 2022-01-04 20:45:03)

Re: Need help!About Tablegrid

Hi,
here is your example according to the description.
A database has been created and a new procedure for rotating a table from a database has been created.
The most difficult part of your task has been created. The rest is a field for your creativity and experimentation. )

A few notes:
-You need to create a form to add / edit database records, dictionary tables (year, grade, empinfo).
-The final result in table 2 and the report is desirable to use as the final report. You may have some difficulty
editing records when trying to directly invoke a record for editing. Use table1 for testing
-The report button can be deleted. In the future, everything can be returned.
-The SQL query (script) is written on the basis that for each employee, in each year there can be only one rating.
Which means that when changing the rating in any year, the record must be edited and not a new record added.


I know there are training courses in the Russian part of the forum, but this is probably not relevant for you.
Maybe someone else can tell you.
In fact, starting with a simple one, you can study it yourself.
Training materials can be found on the forum.
Examples on the forum.
Additional SQL resources on the Internet (sqlitetutorial).
And of course questions on the forum (only specific questions) if you have not found the answer yourself.

Post's attachments

Attachment icon Perform.zip 337 kb, 236 downloads since 2022-01-04 

Re: Need help!About Tablegrid

This is an interesting projects. I want to know which kind of changes will make if we replace years to subjects. For examples: Math, English, History etc etc

Re: Need help!About Tablegrid

if the structure does not change but the names of the fields change, then the names in the SQL query will change.
If the structure of the database changes, the SQL query will need to be rewritten.
The exception is REPORT where the SQL query is not needed.

Re: Need help!About Tablegrid

sparrow! can you upload sample of project as example?

Re: Need help!About Tablegrid

Hi Unforgettable, Sparrow,
I did something a bit similar a while back (for summarising expense claims by category) but used calculated fields together with a lookup table to hold details of what it is you want to show.
The approach enables you to specify which columns to show in the grid, what column headings are displayed in the grid and the position of the columns in the grid - so it can be multi-purpose.
So, in your example, just enter your subject details (history, maths etc) into the table (in the attachment are examples for 'subjects' and for 'years'). 
The main point is that this can be done by the end user rather than having to alter any code.
Maybe it will give you some ideas (but having said that, I think Sparrow's example is technically much better).
Derek.

Post's attachments

Attachment icon unforgettable.zip 682.94 kb, 232 downloads since 2022-01-07 

Re: Need help!About Tablegrid

Thank you derek you have solved my difficulty on which I was working. Here is my one question. Your uploaded project has a limit to show records only 10, if it is unlimited then?

Re: Need help!About Tablegrid

Hi,
If it is unlimited - or if  you have no idea how many columns you'll need, then it's not the best option for you - and why I think Sparrow's option is better because it doesn't have that restriction.
My previous attachment is based on knowing the approximate number of columns that you want to display, although using your example, I would have thought that your approximate number of subjects is known and limited.
It doesn't have to be 10 - that's just the number that I needed at the time for my expenses recording project..  You'd set it up to be as many as you think you need (and then add a few as 'spares' for contingencies;  the 'spares' don't need to be displayed (set the 'showcol' = 'No' in the summary grid and are just kept in reserve in case they're needed - see the attached screenshot)).
Derek.

Post's attachments

Attachment icon screeshot1.jpg 43.22 kb, 89 downloads since 2022-01-07 

Re: Need help!About Tablegrid

Thank you Derek to guide. I want to ask about tables you have checked three tables as dictionary while one was unchecked. Why is it?

Re: Need help!About Tablegrid

Thanks!sparrow & derek!

Re: Need help!About Tablegrid

Hi,
In theory, tables that contain 'static data' or 'lists', for want of better terminology (for example, a choice of colours, a list of countries or, in your example, a list of subjects) are flagged as 'dictionary' tables.
But in practise, it seems to make little difference to the operation of an application.
Derek.

Re: Need help!About Tablegrid

sparrow wrote:

Perhaps you talked about it.
The request is generated dynamically based on the number of returned values.

Can you explain your project, Sparrow?

Re: Need help!About Tablegrid

Get all unique year values

  SQLQuery('SELECT DISTINCT year FROM users ORDER BY year;', Results); 

While the result has not reached the end of the file, create a subquery string and place it in the tmpSel variable.
As many times as years returned.

  while not Results.Eof do
    begin                                                              
      tmpSel := tmpSel + ', (SELECT performance FROM users u WHERE u.name = users.name AND year='+Results.FieldByName('year').asString+') AS "'+Results.FieldByName('year').asString+'" '+ #13#10;
      Results.Next;
    end;
  Results.Close;

Enter the generated query (with tmpSel subqueries) into the table and execute it.

  Form1.TableGrid2.dbSQL := 'SELECT users.name '+ tmpSel +' FROM users Group by users.name;';
  Form1.TableGrid2.dbSQLExecute;

Re: Need help!About Tablegrid

Dear derek,
               I made some modification in your project unforgettable but when data enter more and more form1 take time to load? Why it is? I want to use bar code read on form2. how it will be?

Re: Need help!About Tablegrid

Also works well in Multiselection

Destiny

Re: Need help!About Tablegrid

Dear derek,
               I made some modification in your project unforgettable but when data enter more and more form1 take time to load? Why it is? I want to use bar code read on form2. how it will be?

24 (edited by sparrow 2022-09-05 20:06:20)

Re: Need help!About Tablegrid

Hi all


Unfortunately, this is the result of a large number of calculated fields and queries to rotate the table. TableGrid2 is very slow. If you need a table rotation as a final option for printing or storing in other formats, I recommend using the Report. In the report, use the DB cross-tab function.

Post's attachments

Attachment icon unforget2.zip 339.67 kb, 124 downloads since 2022-09-05 

Re: Need help!About Tablegrid

Hi sparrow,
                Thank to reply. Can you tell about cross-tab function?