存储过程是:
Create Proc Test
(IDList nvarchar(30))
as
begin
Select * from TestTable where ID in (@IDList)
end传递参数 '1','2','3','4'这样传递进去会立即报错,说 参数过多如果要实现这样的功能,存储过程要怎么改?或者说出入的参数如何整整?
Create Proc Test
(IDList nvarchar(30))
as
begin
Select * from TestTable where ID in (@IDList)
end传递参数 '1','2','3','4'这样传递进去会立即报错,说 参数过多如果要实现这样的功能,存储过程要怎么改?或者说出入的参数如何整整?
解决方案 »
- 如何实现这个功能
- 主外键表的查询
- 一个菜菜的问题~~~这个表 怎么做查询
- cursor 里使用 GOTO 重复抓取 cursor循环里的数据
- 请教一个在2张表间更新的问题~急,在线等,谢谢
- SQL
- windows98 以“取消”登入系统,用tcp/ip 直连不能连接到SQL SERVER服务器
- 关于数据查询的问题
- 急求一条sql提取字符语句
- 在SQLSERVER 中怎样用一条语句插入多条记录,(在同一字段中插入有一定规律的数字,第一条记录这一字段值为1,第二条记录这一字段值为2,第三条记录这一字段值为3,等等)
- 我把2000的数据库备份出来,然后在2005上恢复,发现源设备中
- 低端问题,看一下
也可以用exec('...... where ID in('+@IDList+')')
as
begin
execute('Select * from TestTable where ID in (' + @IDList + ')')
end
(IDList nvarchar(30))
as
begin
Select * from TestTable where charindex(','+ltrim(ID)+',',','+@IDList+',')>0
end
(IDList nvarchar(30))
as
begin
EXEC('Select * from TestTable where ID in ('+@IDList+')')
end或者改用CHARINDEX
Select * from TestTable where CHARINDEX(','+LTRIM(ID)+',',','+@IDList+',')>0
(IDlist varchar(30))
as
beginExec('select * from Testtb where ID in('+IDlist+')');end
那么传入参数 应该如何传入 ? exec Test ''1','2','3''这样嘛?
不是数字,是字符串性质的,传到里面去用 in 执行查询
--> Author : jinjazzli
--> Target : ---->1000
--> Date : 2009-12-08 14:41:40
--> Version: SQL Server 2005
---------------------------------------------
--> 测试数据: @tb
create table #t(id int,name varchar(2))
insert into #t
select 1,'aa' union all
select 2,'aa' union all
select 3,'aa' union all
select 4,'bb' union all
select 5,'cc' union all
select 6,'cc' union all
select 7,'ee' union all
select 8,'ff' union all
select 9,'ff'declare @s varchar(10)
set @s='1,3,4'exec('Select * from #t where ID in ('+@s+')')id name
----------- ----
1 aa
3 aa
4 bb(3 行受影响)
drop table #t
(IDlist varchar(30))
as
beginExec('select * from Testtb where ID in('+IDlist+')');end