當前位置:成語大全網 - 新華字典 - ACCESS 字段截取問題

ACCESS 字段截取問題

對姓名字典加遊標來完成,執行該存儲過程:exec Pname 即可。

--設妳的表為:TABLENAME,復合姓名的字段為xms

--再設姓名字典表為:TABLEXM,有字段XM(存儲了姓名)

create procedure Pname

as

declare cursor xmcursor (select xm from tablexm) --建立字典文件(姓名)的遊標,以便逐行查字典

declare @xm varchar(20) --存放姓名

open xmcursor

fetch next from xmcursor into @xm --逐壹提取存在的姓名

while @@fetch_status !=-1 --逐壹提取所有姓名

begin

update tablename set xms=replace(xms,@xm,@xm+'|') --用姓名字典中的姓名加分隔符替換TABLENAME表中的復合姓名

fetch next from xmcursor into @xm --逐壹提取存在的姓名

end

close xmcursor

deallocate xmcursor

go