sqlserver利用存储过程去除重复行的sql语句

还是先上代码吧 ,可以先看 SQL语句去掉重复记录,获取重复记录
<div class="codetitle"><a style="CURSOR: pointer" data="33636" class="copybut" id="copybut33636" onclick="doCopy('code33636')"> 代码如下:

<div class="codebody" id="code33636">
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

我的数据是这样的:因为item_uid是标识列,item_number有重复的,

我想过滤成这样:

顺带说几个在编程的时候遇到的小问题 1.程序 出现 Could not find stored procedure 找不到这个存储过程 因为我的程序数据库有四个,而认连接是A,但实际要执行B库里的存储过程,导致出错, 解决办法1:可在A里面建个一样的存储过程2:在执行连接的时候,替换下数据库就行了 2. asp.net/C# 将存储过程中返回的数据集,填充到dataset/datatable
<div class="codetitle"><a style="CURSOR: pointer" data="25350" class="copybut" id="copybut25350" onclick="doCopy('code25350')"> 代码如下:
<div class="codebody" id="code25350">
sqlConnection conn = new sqlConnection(ConfigurationManager.ConnectionStrings["SolutionsqlServer"].ToString());
sqlCommand cmd = new sqlCommand("Test",conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@MaxId",sqlDbType.Int).Value = 12000; sqlDataAdapter sda = new sqlDataAdapter(cmd);
DataTable dt = new DataTable();
sda.Fill(dt);
在这感谢 http://www.cnblogs.com/liujuncm5/archive/2009/08/31/1557569.html 3.在存储过程里面,写sql语句不能动态不加order by 功能 比如 <div class="codetitle"><a style="CURSOR: pointer" data="3323" class="copybut" id="copybut3323" onclick="doCopy('code3323')"> 代码如下:
<div class="codebody" id="code3323">
--·@new_orderby 是传入参数,不能这样写
select top (10
(2-1)) item_uid from testim order by @new_orderby
--执行这个的时候,sql会出现 The SELECT item identified by the ORDER BY number 1 contains a variable as part
of the expression identifying a column position. Variables are only allowed when
ordering by an expression referencing a column name.

不过我找到解决办法,不过很麻烦,

(第二个回答用 ' sql '进行连接)

(用case end 也行)

4. select into 和 insert into select 两种复制文句 (这里感谢

5.顺便复习下常用的SQL方法语句

代码如下:
declare @name varchar(200) --声明变量
set @name='abcd;def' --赋值
print 'exec len :'+Convert(varchar(10),Len(@name)) --convert(type,value)转换,Len(value)获取大小
print 'exec charindex:'+Convert(varchar(10),CharIndex('e',@name))--CharIndex(find,value) 在value中查找find的位置
print 'not replace:'+@name
print 'exec replace:'+Replace(@name,';','') --用replace替换
print 'exec substring:'+Substring(@name,3)--用substring截取
print @@RowCount --返回上一行代码受影响的行数

作者:chenhuzi

存储过程重复行

相关文章

SELECT a.*,b.dp_name,c.pa_name,fm_name=(CASE WHEN a.fm_n...
if not exists(select name from syscolumns where name=&am...
select a.*,pano=a.pa_no,b.pa_name,f.dp_name,e.fw_state_n...
要在 SQL Server 2019 中设置定时自动重启,可以使用 Window...
您收到的错误消息表明数据库 &#39;EastRiver&#39; 的...
首先我需要查询出需要使用SQL Server Profiler跟踪的数据库标...