Look at the case study VFP: Summary of the results of the query

Source: Internet
Author: User
Tags count

This example applies the knowledge of the GROUP BY clause in the SELECT statement, and for the SELECT statement, refer to the Select SQL command or the SQL language tutorial. This example applies to the Data environment and uses the "People Information table" in the "Data 1" database as the data source for the data environment, and the situation of the database is already looking at the case study VFP: sample database is given in the article, the running interface is shown at the end of this article.

Production steps:

A new form, set its Caption property value to "Summarize query results," set the AutoCenter property value to. T.,width property value is set to 375,height property value set to 250, and the form is saved as "rollup of query results. Scx".

Add a Label control, a combo box control, and a command button control to the form, line the three controls, and set their properties individually:

1. Label control: The Caption property value is set to rollup criteria.

2, combo box control Combo1:rowsourcetype property value set to "N-value", RowSource property value set to "department, gender, education."

3. The command button control command1:caption the property value to total.

Third, right click the blank space of the form, select the Data Environment command, and add the people information table to the data environment. In the Data Environment Designer, drag the title bar of the People information table onto the form to automatically generate a table control. Since the "People information table" is dragged from the data environment by the system, the RecordSource properties and RecordSourceType properties of the table control have been set by the system, and for the convenience of writing code, we modify the Name property value of this table control to " Grid1 ".

Adjust the position of each control on the form appropriately, and the adjusted form Designer is shown in the following illustration:

V. Add event code:

(i) Unload event for the form: close data

(ii) The Click event code for the "Rollup" button Command1:

Private CXTJ,TJ
Cxtj=thisform.combo1.displayvalue
if Empty (CXTJ)   && determine if the list box and text box are empty 
    MessageBox (' Please enter full condition! ', 16, ' system hint ')
   thisform.combo1.setfocus
Else does case 
   alltrim (CXTJ) = ' Department '
      tj= ' department, Count (number) As number, sum (basic salary) as the total wage;
      AVG (basic salary) as average wage, count (number)/reccount () *100 as percent ' case
   alltrim (CXTJ) = ' sex '
      tj= ' sex, COUNT (number) as number, sum (base salary) As total wages,;
      AVG (basic salary) as average wage, count (number)/reccount () *100 as percent ' case
   alltrim (CXTJ) = ' education ' 
      tj= ' degree as education, count (number) as number, count (numbered)/reccount () *100 as% '
   endcase	
   sc= ' into cursor query results '
   Select &TJ. From Personnel information table;
   Group by &CXTJ. &sc.
   Thisform. Grid1.columncount=-1
   thisform.grid1.recordsource= ' query results '
   Thisform.grid1.backcolor=rgb (200,224,248)
   Thisform.grid1.refresh
endif
Clear

Run "Summary of query results. Scx", the interface is shown in the following figure:

Resources:

The basic course of VFP: http://bianceng.cnhttp://www.bianceng.cn/vfpjc/index0.htm

VFP Primary Course: http://bianceng.cnhttp://www.bianceng.cn/cc/index.htm

VFP Intermediate Course: http://bianceng.cnhttp://www.bianceng.cn/mcc/mcc.htm

VFP Advanced Course: http://bianceng.cnhttp://www.bianceng.cn/hcc/hcc.htm

VFP Network Development: http://bianceng.cnhttp://www.bianceng.cn/VFPwz/vfpwlkf.htm

VFP Call API function: http://bianceng.cnhttp://www.bianceng.cn/VFPwz/vfpapi.htm

VFP Report Print: http://bianceng.cnhttp://www.bianceng.cn/VFPwz/vfpreport.htm

VFP Common technique: http://bianceng.cnhttp://www.bianceng.cn/VFPwz/vfpcyjs.htm

VFP Experience Summary: http://bianceng.cnhttp://www.bianceng.cn/VFPwz/vfpjyhz.htm

VFP Control use: http://bianceng.cnhttp://www.bianceng.cn/VFPwz/vfpkjsy.htm

VFP Data processing: http://bianceng.cnhttp://www.bianceng.cn/VFPwz/vfpsjcl.htm

This example code is debugged in the win2003+vfp6.0 environment.

See the full set of "rookie also learn VFP" tutorial

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.