循环后多一个逗号如何去掉s s & group by For i 0 To 5If Check1(i).Value 1 Thens s & Check1(
循环后多一个逗号如何去掉
s = s & "group by "
For i = 0 To 5
If Check1(i).Value = 1 Then
s = s & Check1(i).Caption & " ,"
Debug.Print s
End If
Next
这样出来的结果就是:
select 油田名,区块,sum(进尺) as 总产量 from jibenxinxi,scsj where jibenxinxi.井号=scsj.井号 and 油田名='长庆油田' and 区块='001' group by 油田名,
select 油田名,区块,sum(进尺) as 总产量 from jibenxinxi,scsj where jibenxinxi.井号=scsj.井号 and 油田名='长庆油田' and 区块='001' group by 油田名,区块,
后面总多一个 怎么解决....
[解决办法]
学会举一反三,刚才给你的例子可以当成一个标准的生成方法:
dim sGroupBy as string
s = s & "group by "
For i = 0 To 5
If Check1(i).Value = 1 Then
if sGroupBy="" then
sGroupBy=Check1(i).Caption
else
sGroupBy = sGroupBy & "," & Check1(i).Caption
end if
End If
Next
s=s & sGroupBy
debug.print s
