注册 登录
编程论坛 VFP论坛

如何按kc字段判断生成新字段cc,并在新字段中填入场别

反璞归真 发布于 2024-05-18 07:52, 237 次点击
只有本站会员才能查看附件,请 登录



001-042  第一场
043-084  第二场
085-118  第三场
119-160  第四场
161-202  第五场
203-244  第六场
245-278  第七场
按照这样在001-042考场后边列增加cc字段并填入第一场,以此类推,求大师帮忙
2 回复
#2
sdta2024-05-18 08:14
VFP9代码
lc = 'ICASE(BETWEEN(kc,"001","042"),"第一考场", BETWEEN(kc,"043","084"),"第二考场", BETWEEN(kc,"085","118"),"第三考场", BETWEEN(kc,"119","160"),"第四考场", BETWEEN(kc,"161","202"),"第五考场", BETWEEN(kc,"203","244"),"第六考场","第七考场")'
SELECT Kc, &lc Cc FROM Kc
#3
schtg2024-05-19 06:15
2楼的好方法,也可以试一试哈
只有本站会员才能查看附件,请 登录

程序代码:
select *,space(12) as cc from kc into cursor tt readwrite
select tt
replace cc with "第一场" for val(kc) >=  1  and val(kc) <=  42
replace cc with "第二场" for val(kc) >=  43 and val(kc) <=  84  
replace cc with "第三场" for val(kc) >=  85 and val(kc) <= 118  
replace cc with "第四场" for val(kc) >= 119 and val(kc) <= 160  
replace cc with "第五场" for val(kc) >= 161 and val(kc) <= 202  
replace cc with "第六场" for val(kc) >= 203 and val(kc) <= 244
replace cc with "第七场" for val(kc) >= 245 and val(kc) <= 278

go top
browse

还有这种考场分布规律性不强的,可以单列一个考场分配表(_ls),然后试一试下面的方法:
程序代码:
set safety off
close all

create dbf _ls(kc1 c(5),kc2 c(5),kcm c(12))
insert into _ls(kc1,kc2,kcm) values("001","042","第一考场")
insert into _ls(kc1,kc2,kcm) values("043","084","第二考场")
insert into _ls(kc1,kc2,kcm) values("085","118","第三考场")
insert into _ls(kc1,kc2,kcm) values("119","160","第四考场")
insert into _ls(kc1,kc2,kcm) values("161","202","第五考场")
insert into _ls(kc1,kc2,kcm) values("203","244","第六考场")
insert into _ls(kc1,kc2,kcm) values("245","278","第七考场")

select *,space(12) as cc from kc into table tt
select _ls
go top
scan
   kcs1 = kc1
   kcs2 = kc2
   kcmc = kcm
   update tt set cc = alltrim(kcmc) where kc >= kcs1 and kc <= kcs2
endscan

select tt
go top
browse



[此贴子已经被作者于2024-5-19 06:31编辑过]

1