请教各位,数据库有一表,表中有N个字段,其中一个如下:
fphm
01234
01234
01235
01236
01237
01239
01239
01239
01240
01241
01241
01245
01246
.......
求一算法或函数,得到如下结果:
01234-01237,01239-01241,01245-01246
谢谢帮助
fphm
01234
01234
01235
01236
01237
01239
01239
01239
01240
01241
01241
01245
01246
.......
求一算法或函数,得到如下结果:
01234-01237,01239-01241,01245-01246
谢谢帮助
select * from table where fphm between '01239' and '01241'
select * from table where fphm between '01245' and '01246'
'数据库数据
Dim a(9) As String
a(0) = "01"
a(1) = "02"
a(2) = "03"
a(3) = "04"
a(4) = "07"
a(5) = "08"
a(6) = "10"
a(7) = "11"
a(8) = "12" Dim intIndex, i As Integer
Dim b() As String '存放组合后的数组
Dim strStart As String '存放开始数据
Dim strEnd As String '存放结束数据
Dim strCom As String '存放组合数据
'初始化数据
strStart = a(0)
strEnd = a(0)
i = 0 '循环处理数据
For intIndex = 1 To 8 If (CInt(a(intIndex)) = CInt(strEnd)) Or (CInt(a(intIndex)) = CInt(strEnd) + 1) Then
'数据连续的情况
''''''
Else
'数据不连续的情况
strCom = strStart & "-" & strEnd
i = i + 1
ReDim Preserve b(i)
b(i - 1) = strCom
strStart = a(intIndex)
End If
strEnd = a(intIndex)
'最后数据
If intIndex = 8 Then
strCom = strStart & "-" & strEnd
ReDim Preserve b(i + 1)
b(i) = strCom
End If
Next
End Sub以上是我的大概做法,楼主可以参考修改下,数据库取数据时候要order by一下啊.