sql 存储过程 去除重复行 sql 常用方法

 

代码
ALTER procedure [dbo].[PROC_ITEMMASTER_GETUNIQUE] @PAGEINDEX INT,@uid int,@itemnumber varchar(50)
AS begin tran
--开始事务
drop table [ItemMaster].[dbo].[testim]
--删除表--把不重复记录转存到testim中
select
* into [ItemMaster].[dbo].[testim] from [ItemMaster].[dbo].[dat_item_master] where item_uid in(select min(item_uid) as item_uid from [ItemMaster].[dbo].[dat_item_master] group by item_number) and status=0

select top
10 * from [ItemMaster].[dbo].[testim] where item_uid not in (select top (10*(@PAGEINDEX-1)) item_uid from [ItemMaster].[dbo].[testim])and owneruid=@uid and item_number like @itemnumber+'%'
--判断是否出错
if @@error<>0
begin
rollback tran
--出错则回滚
end
else
begin
--否则提前事务
commit tran
end

 

posted @ 2010-10-29 10:03  Q玲珑  阅读(273)  评论(0编辑  收藏  举报