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

游標實例

系統 1925 0

今天寫了一個游標,但是不知道怎么在這游標里定義一個變量來記錄執行時影響條數,并插入兩條數據時就跳出循環結束游標。

沒有想出轍,實屬頭疼。附代碼如下:

      --游標

declare @userID uniqueidentifier--userid

declare y_curr cursor for

select top 2 userID from Hope_Users_db.dbo.u_Users order by addTime desc



open y_curr --打開游標

fetch next from y_curr into @userID ----開始循環游標變量

while(@@fetch_status=0)---返回被FETCH  語句執行的最后游標的狀態,而不是任何當前被連接打開的游標的狀態。

begin

	   if exists (select * from Q_enterprise where userID = @userID)

		  begin

		     print @userID

		  end

		else

		  begin

			   print @userID

			   insert into Q_enterprise

			   select distinct u.userID, u.userType,u.SyncCharityId as CharityId,u.userTrueName,u.userLogo,0 as donationAmount,e.enterpriseContactMobile,

			   e.enterprisePurpose,0 as enterpriseLongitude,0 as enterpriseLatitude,'' as Infoproportion,0 as sharesum,0 as praisesum,

			   0 as Donationsum,0 as Farvritessum,0 as Donationsum30,u.addTime,'' as updatetime

			   from Hope_Users_db.dbo.u_Users u

			   inner join Hope_Donation_DB.dbo.d_Donation d

			   on u.userID=d.userID

			   inner join Hope_Users_db.dbo.u_Enterprise e

			   on u.userID = e.userID

			   where u.userID=@userID

		  end

      fetch next from y_curr into @userID --開始循環游標變量

end

close y_curr--關閉游標

deallocate y_curr --釋放游標

go


    

游標實例


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

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

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 东方市| 赣榆县| 常德市| 普格县| 商城县| 鄂托克前旗| 巧家县| 博罗县| 云和县| 施秉县| 利川市| 高密市| 德安县| 阿尔山市| 房山区| 许昌市| 阳山县| 巢湖市| 镇康县| 安福县| 白银市| 梧州市| 城步| 衢州市| 平武县| 公主岭市| 平远县| 海晏县| 泾阳县| 定襄县| 黑龙江省| 林甸县| 林口县| 东丽区| 隆尧县| 右玉县| 葵青区| 大英县| 大城县| 阜新| 十堰市|