亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

SQL server使用自定義函數(shù)以及游標(biāo)

 更新時(shí)間:2011年10月31日 23:22:06   作者:  
最近忙于動(dòng)態(tài)監(jiān)測(cè)軟件的開(kāi)發(fā),處理有關(guān)標(biāo)準(zhǔn)宗地編碼和區(qū)段編碼關(guān)系,關(guān)系如下表所示

編號(hào)

標(biāo)準(zhǔn)宗地編碼(landCode)

所在區(qū)段編碼(sectCode)

1

131001BG001

G001

2

131001BG002

G001

3

131001BG003

G001

4

131001BG004

G002

5

131001BG005

G003

現(xiàn)在需要將表中的數(shù)據(jù)轉(zhuǎn)換為如下表所示結(jié)果:

編號(hào)

區(qū)段編碼

包含的標(biāo)準(zhǔn)宗地

1

G001

131001BG001,131001BG002,131001BG003

2

G002

131001BG004

3

G003

131001BG005

在SQL server數(shù)據(jù)庫(kù)中,創(chuàng)建自定義函數(shù),通過(guò)游標(biāo),將表的數(shù)據(jù)轉(zhuǎn)化為結(jié)果表,函數(shù)代碼如下所示:

復(fù)制代碼 代碼如下:

create function combstr(@name nvarchar(50))
returns nvarchar(300)
as
begin
declare @resultStr nvarchar(300)
declare @tempStr nvarchar(500)
declare @flag int
declare myCur cursor --定義游標(biāo)
For(select landCode from land where sectCode=@name )
open myCur –-打開(kāi)游標(biāo)
fetch next from myCur into tempStr –將游標(biāo)下移
set @flag=0
while @@fetch_status=0
begin
if @flag=0
begin
set @resultStr=@tempStr
end
else
begin
set @resultStr=@resultStr+','+@tempStr
end
set @flag=@flag+1
fetch next from myCur into @tempStr
end
close myCur
deallocate myCur
return @result
end

相關(guān)文章

最新評(píng)論