您的位置:程序门 -> vb -> 基础类



如何解决这个数据转换?


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


如何解决这个数据转换?
发表于:2007-03-29 21:06:30 楼主
我在数据库表1中有一个序列字段code,例如:
code                                     city
420104820108244                 ????
420103852102585                 ????
420102775214122                 ????
在表2中:
code             city
420104           城东
420102           城西
420103           城南
怎样才可以把表1中的每条记录中的前5位数字对应表2中的相应字段转换过来?
急!叩谢!
发表于:2007-03-29 21:14:331楼 得分:0
如果是sql   server的话,   可以这样:

update   表1   set   city   =   (select   city   from   表2   where   表2.code   =   substring(表1.code,   1,   5))
发表于:2007-03-29 21:17:022楼 得分:0
如果是access的话:
update   表1   set   city   =   (select   city   from   表2   where   表2.code   =   leftg(表1.code,   5))
发表于:2007-03-29 21:18:163楼 得分:0
option   explicit

private   sub   form_load()
dim   thiscode   as   long
dim   thiscity   as   string

  getcity   thiscode,   thiscity
 
  'thiscity   为所求的城市
end   sub


private   sub   getcity(thiscode   as   long,   thiscode   as   string)

dim   code()   as   long
dim   city()   as   string

dim   citybyte()   as   byte
dim   citybyte()   as   byte

open   "code.dat "   for   binary   as   #1
redim   citybyte(n)     'code   的数量   -1

get   #1,   ,   citybyte
close   #1

open   "city.dat "   for   binary   as   #1
redim   citybyte(n)   '   city   的数量   -1

get   #1,   ,   citybyte
close   #1


code   =   split(citybyte,   " ¦ ")
city   =   split(citybyte,   " ¦ ")

dim   i   as   long
for   i   =   lbound(citybyte)   to   ubound(citybyte)
        if   city(i)   =   thiscode   then
                thiscode   =   city(i)
                exit   for
        end   if
next

end   sub
发表于:2007-03-29 21:28:274楼 得分:0
谢谢!
发表于:2007-03-30 12:46:485楼 得分:0
恭喜,请揭贴!
发表于:2007-03-30 13:10:556楼 得分:0
这里有解答   http://www.haolla.com/girls


快速检索

最新资讯
热门点击