select * from tid where id in 数组

解决方案 »

  1.   

    declare @str as varchar(100)
    set @str = '1,2,3'exec('select * from tb where tid in ('+ @str + ')')
      

  2.   

    try:
    select * from table1 where charindex(','+rtrim(tid)+',',','+@tid+',')>0
      

  3.   

    --> 测试数据: #T
    if object_id('tempdb.dbo.#T') is not null drop table #T
    create table #T (tid int,tname varchar(3))
    insert into #T
    select 1,'aaa' union all
    select 2,'bbb' union all
    select 3,'ccc' union all
    select 4,'ddd' union all
    select 5,'eee' union all
    select 6,'fff' union all
    select 7,'ggg' union all
    select 8,'hhh' union all
    select 9,'iii' union all
    select 10,'jjj'select * from #T where tid in(1,2,3) -->在你的前台将int[] a里的元素,组成一个"1,2,3"的STRING。
    /*
    tid         tname
    ----------- -----
    1           aaa
    2           bbb
    3           ccc
    */
      

  4.   

    其他内容见:http://topic.csdn.net/u/20080512/14/687202c1-5ea2-493e-b86c-e43a8e12f277.html
      

  5.   

    select * from 表table1 
    where tid in(1,4,6)
      

  6.   

    declare @t table(tid int,tname varchar(8))
    insert into @t values(1 ,'aaa') 
    insert into @t values(2 ,'bbb') 
    insert into @t values(3 ,'ccc') 
    insert into @t values(4 ,'ddd') 
    insert into @t values(5 ,'eee') 
    insert into @t values(6 ,'fff') 
    insert into @t values(7 ,'ggg') 
    insert into @t values(8 ,'hhh') 
    insert into @t values(9 ,'iii') 
    insert into @t values(10,'jjj') declare @tid varchar(40)
    set @tid='1,4,7'
    select * from @t where charindex(','+rtrim(tid)+',',','+@tid+',')>0
      

  7.   

    select * from table1 where charindex(','+rtrim(tid)+',',','+@tid+',')>0
      

  8.   

    declare @t table(tid int,tname varchar(8))
    insert into @t values(1 ,'aaa') 
    insert into @t values(2 ,'bbb') 
    insert into @t values(3 ,'ccc') 
    insert into @t values(4 ,'ddd') 
    insert into @t values(5 ,'eee') 
    insert into @t values(6 ,'fff') 
    insert into @t values(7 ,'ggg') 
    insert into @t values(8 ,'hhh') 
    insert into @t values(9 ,'iii') 
    insert into @t values(10,'jjj') declare @tid varchar(40)
    set @tid='1,4,7'
    select * from @t where charindex(','+rtrim(tid)+',',','+@tid+',')>0
      

  9.   

    大大们,万一 表table1里 有一千条数据而不是十条,那还是用临时表里插1000条信息吗?那不是要写很多???
      

  10.   

    declare @t table(tid int,tname varchar(8)) 这是创建一个表变量。不相当于创建一个临时表吗?然后向这个表变量里插入数据...???
      

  11.   

    declare @t table(tid int,tname varchar(8))
    insert into @t values(1 ,'aaa') 
    insert into @t values(2 ,'bbb') 
    insert into @t values(3 ,'ccc') 
    insert into @t values(4 ,'ddd') 
    insert into @t values(5 ,'eee') 
    insert into @t values(6 ,'fff') 
    insert into @t values(7 ,'ggg') 
    insert into @t values(8 ,'hhh') 
    insert into @t values(9 ,'iii') 
    insert into @t values(10,'jjj') declare @tid varchar(40)
    set @tid='1,4,7'
    select * from @t where charindex(','+rtrim(tid)+',',','+@tid+',')>0是测试用的表变量,条件你1,4,7是你传的值
      

  12.   

    人家这是写测试用例呀,这样可以不?create table ta(tid int,tname varchar(8))
    insert into ta values(1 ,'aaa') 
    insert into ta values(2 ,'bbb') 
    insert into ta values(3 ,'ccc') 
    insert into ta values(4 ,'ddd') 
    insert into ta values(5 ,'eee') 
    insert into ta values(6 ,'fff') 
    insert into ta values(7 ,'ggg') 
    insert into ta values(8 ,'hhh') 
    insert into ta values(9 ,'iii') 
    insert into ta values(10,'jjj') 
    go
    declare @tid varchar(40)
    set @tid='1,4,7'select * 
    from ta 
    where charindex(','+rtrim(tid)+',',','+@tid+',')>0
    drop table ta
      

  13.   

    我日...不好意思我自己想复杂了...看歪了。谢谢  happyflystone ..........晕,真写晕的了,老想着用个临时表把那组字符串给装起来...太白痴了 ...晕