日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

(SQL游標(biāo)) 整合省市

系統(tǒng) 2024 0

declare @ParentID int
declare @num int
set @num =0
--聲明一個(gè)游標(biāo)mycursor,select語(yǔ)句中參數(shù)的個(gè)數(shù)必須要和從游標(biāo)取出的變量名相同
declare mycursor cursor for
select ProID as ParentID from Bms_Province p

--打開(kāi)游標(biāo)
open mycursor

--從游標(biāo)里取出數(shù)據(jù)賦值到我們剛才聲明的2個(gè)變量中
fetch next from mycursor into @ParentID

--判斷游標(biāo)的狀態(tài)
--0 fetch語(yǔ)句成功
---1 fetch語(yǔ)句失敗或此行不在結(jié)果集中
---2被提取的行不存在
while (@@fetch_status=0)
begin

--顯示出我們每次用游標(biāo)取出的值
print '游標(biāo)成功取出一條數(shù)據(jù)'

set @num =@num+1
print @num
insert into Bms_Areas
select
(case when T.CityID=0 then 0 else -99 end ) as ParentID,
(case when T.CityID=0 then '0'+CONVERT(VARCHAR(10),T.ProID)
else '00'+CONVERT(VARCHAR(10),T.CityID) end) as AreaCode,
T.ProName as AreaName,'' as Notes,
(case when T.CityID=0 then 1 else 2 end) as LevelNum,
0 as IsDefault,1 as IsValid,0 as IsDel
from (
select p.ProID,p.ProName,p.ProSort,0 as CityID,p.ProRemark from Bms_Province p where ProID=@ParentID
union select c.ProID,c.CityName,c.CitySort,c.CityID,'' as ProRemark from Bms_City c where ProID=@ParentID
) T order by CityID

UPDATE T SET ParentID =
(select top 1 AreaID from Bms_Areas where ParentID=0 order by AreaID desc)
from (select * from Bms_Areas where ParentID=-99 and AreaID>
(select top 1 AreaID from Bms_Areas where ParentID=0 order by AreaID desc)) T


--用游標(biāo)去取下一條記錄
fetch next from mycursor into @ParentID
end
--關(guān)閉游標(biāo)
close mycursor
--撤銷游標(biāo)
deallocate mycursor

(SQL游標(biāo)) 整合省市


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號(hào)聯(lián)系: 360901061

您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長(zhǎng)非常感激您!手機(jī)微信長(zhǎng)按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對(duì)您有幫助就好】

您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長(zhǎng)會(huì)非常 感謝您的哦?。。?/p>

發(fā)表我的評(píng)論
最新評(píng)論 總共0條評(píng)論
主站蜘蛛池模板: 涟水县| 乐安县| 东乡族自治县| 鄄城县| 喀什市| 澳门| 鸡泽县| 左云县| 大关县| 五大连池市| 宽甸| 清原| 巢湖市| 肇东市| 玛多县| 邓州市| 孝义市| 德格县| 体育| 平邑县| 蒙自县| 淳安县| 桑植县| 乌兰县| 德钦县| 仙桃市| 博白县| 庄浪县| 宝鸡市| 大埔区| 喀什市| 新津县| 咸丰县| 嫩江县| 萨嘎县| 乐陵市| 两当县| 鹤山市| 古田县| 维西| 浏阳市|