* 构造VFP中SQL命令字段表达式
CREATE CURSOR km (xk c(10))
INSERT INTO km VALUES ("语文")
INSERT INTO km VALUES ("数学")
INSERT INTO km VALUES ("英语")
INSERT INTO km VALUES ("物理")
INSERT INTO km VALUES ("化学")
INSERT INTO km VALUES ("思想品德")
INSERT INTO km VALUES ("历史")
lcStr = "zkzh, xm"
SCAN
lcStr = ...
RECNO()>RECCOUNT()-N
CREATE CURSOR Cj (班级 C(5),姓名 C(10),总分 N(4),班级名次 N(6),年级名次 N(6))
=RAND(-1)
FOR I=1 TO 1000
FOR J=1 TO 50
INSERT INTO Cj (班级,姓名,总分) VALUES ("B"+PADL(I,4,"0"),SYS(2015),RAND()*100)
ENDFOR
ENDFOR
INDEX ON 班级-STR(总分,4) TAG px DESCENDING
* 班级名次
mc=1 && 记录班级名次
nzf=0 &am...
create cursor tt (a1 i,a2 i,a3 i,a4 i,a5 i,a6 i,a7 i,a8 i,a9 i,a10 i,a11 i)
rand(-1)
for lnI=1 to 11
append blank
nzds=0
for lnJ=(lnI-1)*11+1 to lnI*11
nzds=nzds+1
replace (field(nzds)) with lnJ*rand()
endfor
endfor
lcStru=""
for lnI=1 to fcount()
...
* 测试表
CREATE CURSOR T (BH C(4),B1 N(4),B2 N(4),B3 N(4),B4 N(4))
INSERT INTO T VALUES ([0001],1200,1000,800,600)
INSERT INTO T VALUES ([0002],1100,900,700,500)
INSERT INTO T VALUES ([0003],1900,1700,1500,1300)
SELECT *,000000 小计 FROM T INTO CURSOR TEMP READWRITE
LCSTR=[]
* 生成字段名列表
FOR I=...
用第一条记录各字段的对应值替换原有表结构中的字段名
clear all
create cursor aa (a c(10),b c(10))
insert into aa values ("a1","b1")
scatter to cc
for lni=1 to fcount()
alter table aa rename column (field(lnI)) to &cc[lnI]
endfor
browse
* 该代码的前提是表结构相同,字段顺序相同,记录数相同,两表关键字段内容相同(同样适用关键字段内容不正确的情况,前提是记录顺序相同,这时用RECNO()作为索引关键字)
clear
create cursor tt (a1 c(10),a2 c(10),a3 c(10))
insert into tt values ("0001","abcd","aa")
insert into tt values ("0002","abcd","ab")
insert into tt values ("0003","abcd","ac")
insert into tt v...
* 说明:原表为Cjb.Dbf<见附件>,准考证号前4位为学校编码,要求根据成绩按 学校编码 分类排出 名次,排出的结果见 名次 字段,遇到不同的学校编码,名次从1开始排,当成绩相同时排出的名次一样,最后结果如:1133567
* 代码为VFP9版本
T1=Seconds()
Select Left(准考证号,4) 学校编码,准考证号,总成绩,000000 名次 From Cjb Order By 学校编码,总成绩 Desc Into Cursor Mcb ReadWrite
Go Top
Scatter Memva...
Clear
Clear All
Close Databases
Set Collate To "MACHINE"
T1=Seconds()
Local Akm[6]
Akm[1]="语文"
Akm[2]="数学"
Akm[3]="英语"
Akm[4]="物理"
Akm[5]="化学"
Akm[6]="总成绩"
Use Cjb In 0
Create Cursor 前N名 (准考证号 C (10),语文 N(6),数学 N(6),英语 N(6),物理 N(6),化学 N(6),总成绩 N(6))
Append Fr...
Reccount()-Recno()+1<=N
N可以是任意的正整数
Set Collate To "MACHINE"
Set Talk Off
T1=Seconds()
Clear
Close DataBases
Local Akm[2],Apm[7],Afs[2,7],TableName[2],cXbm
cXbm="校编码"
TableName[1]="成绩"
TableName[2]="成绩分析"
Akm[1]="语文"
Akm[2]="数学"
Apm[1]=1
Apm[2]=50
Apm[3]=100
Apm[4]=200
Apm[5]=300
Apm[6]=400
Apm[7]=500
Se...
LPARAMETERS CTABNAME
GO BOTTOM
*--- 检查最后一条记录是否为"小计"行
IF AT("小计",EVALUATE(FIELD(1)))>0
MESSAGEBOX("已经有小计记录",64,"系统信息")
RETURN
ENDIF
*--- 在数据表最后插入一条记录
INSERT INTO (CTABNAME) ((FIELD(1))) VALUES (PADC("小计",FSIZE(FIELD(1)),"-"))
FOR I=NZDS TO FCOUNT()
IF TYPE(FIELD(I))="N"
...
Select * From 表名 Where 字段名 In (Select 字段名 From 表名 Group By 字段名 Having Count(*)>1) Order By 字段名
问题网址:http://bbs.bccn.net/thread-442165-1-1.html
* 生成测试数据
create cursor tt1 (记录行 i,字段名 c(10),值 i) && 临时表
create cursor tt (a1 i,a2 i,a3 i,a4 i,a5 i,a6 i,a7 i,a8 i,a9 i,a10 i,a11 i)
for lnI=1 to 11
append blank
nzds=0
for lnJ=(lnI-1)*11+1 to lnI*11
nzds=nzds+1
replace...
clear all
create cursor t3 (学号 c(4),姓名 c(8),课目 c(10),成绩 n(3))
create cursor t1 (学号 c(4),姓名 c(8),数学 n(3),语文 n(3))
insert into t1 values ("1001","张三",102,120)
insert into t1 values ("1002","李四",119,108)
nzds=2
scan
scatter to azd
for lnI=1 to fcount("t1")-nzds
insert into ...
Note 行转列
clear all
create cursor t2 (学号 c(4),姓名 c(8),课目 c(10),成绩 n(3))
insert into t2 values ("1001","张三","数学",102)
insert into t2 values ("1001","张三","语文",120)
insert into t2 values ("1002","李四","数学",119)
insert into t2 values ("1002","李四","语文",108)
select distinct 课目 from t2 into array...
Clear
Clear All
CREATE CURSOR test (数字 N(5,0))
INSERT INTO test values(7)
INSERT INTO test values(88)
INSERT INTO test values(9)
INSERT INTO test values(8)
INSERT INTO test values(103)
INSERT INTO test values(12)
INSERT INTO test values(11)
INSERT INTO test values(102)
INSERT INTO test...
CREATE CURSOR test (数字 N(5,0))
INSERT INTO test values(7)
INSERT INTO test values(88)
INSERT INTO test values(9)
INSERT INTO test values(8)
INSERT INTO test values(103)
INSERT INTO test values(12)
INSERT INTO test values(11)
INSERT INTO test values(102)
INSERT INTO test values(101)
Sort...