Sql server中cursor的使用
来源:互联网 发布:家庭ktv 知乎 编辑:程序博客网 时间:2024/06/04 19:09
ALTER PROCEDURE [dbo].[usp_cm_mapping_reference_id_commonplace]
AS
SET NOCOUNT ON;
BEGIN
declare @master_location_id int;
declare @commonplace_name varchar(300);
declare my_cursor cursor for
select master_location_id,common_place_name
from master_location_common_place group by master_location_id,common_place_name
having count(*)>1
open my_cursor
fetch next from my_cursor into @master_location_id,@commonplace_name
while @@FETCH_STATUS= 0
Begin
--logic
delete from master_location_common_place where master_location_id=@master_location_id andcommon_place_name=@commonplace_name
and master_location_common_place_id not in
(select min(master_location_common_place_id) from master_location_common_place
where master_location_id=@master_location_id andcommon_place_name=@commonplace_name)
--Get id of insert
set @new_master_location_id=SCOPE_IDENTITY();
--reference_id
select @reference=reference_id from master_location where master_location_id=@master_location_id;
if(isnull(@reference,'')='')
Begin
update master_location set reference_id=@reference_id wheremaster_location_id=@master_location_id;
End
else
Begin
if(isnull(@reference_id,'')!='')
Begin
if(charIndex(cast(@reference_id as varchar),@reference)=0)
Begin
set @reference=@reference+','+cast(@reference_id as varchar);
update master_location set reference_id=@reference wheremaster_location_id=@master_location_id;
End
End
End
fetch next from my_cursor into @master_location_id,@commonplace_name
End
close my_cursor
deallocate my_cursor
END
- Sql server中cursor的使用
- 在sql server中关于游标cursor的使用
- SQL Server学习:存储过程中Cursor(游标)的使用
- Sql Server:Cursor的例子
- sql server游标的Cursor for后面使用变量
- sql server游标的Cursor for后面使用变量
- SQL Server使用触发器删除重复的列(Delete duplicate rows using cursor in SQL Server)
- pl/sql中光标cursor的使用笔记
- sql server 游标的语法cursor
- Sql Server cursor 的使用处理重复数据 动态拼接 SQL语句
- Sql server中的Cursor
- SQL SERVER CURSOR
- SQL Server CURSOR
- SQL Server游标,Cursor
- android中cursor的使用
- Android中Cursor的使用
- PL/SQL中Ref Cursor的应用
- PL/SQL Cursor游标的基本使用
- 一起看代码来玩玩QT之01Hello world
- Ionic基础——幻灯指令 ion-slide-box
- iOS(CoreGraphics)画带箭头的框
- 大淘营淘宝店铺宝贝复制专家3.56 破解记录 不怕升级
- ZOJ 2970 Faster, Higher, Stronger(排序)
- Sql server中cursor的使用
- python开发_常用的python模块及安装方法
- 一些java小细节问题
- leetcode笔记--Odd Even Linked List
- 枚举设备栈
- 一次服务器环境搭建的记录(nginx+php+subversion)
- 手动编译源码升级gcc4.8.2
- 关于eclipse中recycleview/cardview的引入(环境搭建)
- windows系统下Python环境的搭建