社区
MS-SQL Server
帖子详情
在存储过程中,怎么用not in
youxihaha
2003-12-15 08:03:09
比如我想传入这样一个字符串(123,212,32)
然后select * from users where userid not in (123,212,32)
...全文
130
5
打赏
收藏
在存储过程中,怎么用not in
比如我想传入这样一个字符串(123,212,32) 然后select * from users where userid not in (123,212,32)
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
5 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
vileboy
2003-12-15
打赏
举报
回复
declare @krs table (NUM INT)
DECLARE @X VARCHAR(8000)
SET @X='123,212,32,'
WHILE @X<>''
BEGIN
INSERT INTO @KRS (NUM) VALUES (LEFT(@X,(CHARINDEX(',',@X)-1) ) )
SET @X=RIGHT(@X,LEN(@X)-CHARINDEX(',',@X))
END
select * from users where userid not in(select num from @drs)
youngby
2003-12-15
打赏
举报
回复
crate pro myPro
@1 varchar(20),
@2 varchar(20),
@3 varchar(20)
as
exec('select * from users where userid not in ('+@1+','+@2+','+@3+')')
go
txlicenhe
2003-12-15
打赏
举报
回复
测试:
create table t1(a int)
insert t1 values(1)
insert t1 values(2)
insert t1 values(3)
insert t1 values(4)
go
create proc test @s varchar(20)
as
exec('select * from t1 where a not in '+@s)
go
-- 调用
exec test '(1,2)'
a
-----------
3
4
(所影响的行数为 2 行)
j9988
2003-12-15
打赏
举报
回复
有点错
select * from users where charindex(','+rtrim(userid)+',' ,','+@字符串+',')>0
j9988
2003-12-15
打赏
举报
回复
select * from users where charindex(','+rtrim(userid)+',' ,@字符串)>0
OR:
exec('select * from users where userid not in ('+@字符串+')')
分页
存储过程
,综合了NOT_IN和SET ROWCOUNT
分页
存储过程
,自己把“NOT_IN”和“SET ROWCOUNT”两种方式综合了一下。“SET ROWCOUNT”算法不变,“NOT_IN”排序时加了主键字段,这样速度提升了很多而且结果是单向唯一的,但不是双向可逆的。“SET ROWCOUNT”没有速度问题,“NOT_IN”排序加了主键字段后在30W记录时对非索引字段、非聚合字段的排序翻一页不过3秒钟,还可以吧:P----------------
存储过程
分页【NOT IN】和【>】效率大PK 千万级别数据测试结果
use TTgoif exists (select * from sysobjects where name='Tonge')drop table Tongecreate table Tonge( ID int primary key identity(1,1), NAME varchar(100), PWD varchar(100), PHONE varchar(100), BORNDATE d...
MS-SQL Server
34,875
社区成员
254,639
社区内容
发帖
与我相关
我的任务
MS-SQL Server
MS-SQL Server相关内容讨论专区
复制链接
扫一扫
分享
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章