意思大概是这样的(但是肯定会报错):declare @str varchar(200);create table #t(i int);
insert into #t
select 1
union all
select 3
union all
select 4
union all
select 5;set @str='8,9';select * from #t
where i in (@str);drop table #t;
传入一个带有8,9,0这样的变量到非动态SQL的IN,(不要变量SQL哦,考虑编译和执行的效率)
insert into #t
select 1
union all
select 3
union all
select 4
union all
select 5;set @str='8,9';select * from #t
where i in (@str);drop table #t;
传入一个带有8,9,0这样的变量到非动态SQL的IN,(不要变量SQL哦,考虑编译和执行的效率)
解决方案 »
- 大数据量更新,如何提高速度
- 安装进程的自动关闭问题。
- 请教高手sql联结查询问题
- sql2005登录的问题
- [求教] 用 alter table 把原有表的字段更改为 primary key 或 foreign key 的方法?
- 求解,分数多多
- (狂送分100)在线等,大侠帮忙啊!!.NET链接数据库取不出数据的问题
- 从EXCEL导入到SQL中,因某一字段数据量太大导致出错,为什么(想了一个笨办法,但还有更好的办法吗)
- 如何实现这样的功能:将多个表格相同定义的字段连接成一个新表,或者生成一个视图?哪种方法更好些?
- Oracle 表与视图问题
- 求解一个SQL语句的执行效率问题
- 好双多SQL面试题
insert into #t
select 1
union all
select 3
union all
select 4
union all
select 5;set @str1=4
set @str2=5;select * from #t
where i=@str1 or i=@str2;drop table #t;/**
i
-----------
4
5(所影响的行数为 2 行)
**/
declare @str varchar(200);create table #t(i int);
insert into #t
select 1
union all
select 3
union all
select 4
union all
select 5;set @str='1,2,3';EXEC('select * from #t where i in ('+@str+')');
/*
i
-----------
1
3(2 行受影响)*/
drop table #t;
insert into #t
select 1
union all
select 3
union all
select 4
union all
select 5;set @str='3,8,9';DECLARE @xmlData xml
SET @xmlData = CAST('<r><i>'+REPLACE(@str,',','</i><i>')+'</i></r>' AS XML)
SELECT * FROM #t WHERE EXISTS(SELECT 1 from
(SELECT a.i.value('.','int') AS d FROM @xmlData.nodes('//i') a(i)) t WHERE t.d = i)drop table #t;