SQL语句 where in(张三,张三,李四,张三,李四,张三)。怎么使记录集的顺序和()里的条件顺序一致。包括重复的要一样
数据库为:张三 1
李四 5
王五 6结果集为:
张三 1
张三 1
李四 5
张三 1
李四 5
张三 1还有个问题,客户端游标循环占用不占用服务器的负载?是记录集保存到客服端,和服务器无关了吗?

解决方案 »

  1.   

    where in(张三,张三,李四,张三,李四,张三)你  IN   再多的 ‘张三’  最终出来的记录,也只会是一条啊想你要的结果集, 得连接SQL语句 where 名字 = ’张三‘
    union all
    SQL语句 where 名字 = ’张三‘
    union all
    SQL语句 where 名字 = ’李四‘
    union all
    SQL语句 where 名字 = ’张三‘
    union all
    SQL语句 where 名字 = ’李四‘
    union all
    SQL语句 where 名字 = ’张三‘
      

  2.   

    我的意思是 执行SQL语句取得数据集以后,用的客户端游标 和服务器有没关系不是SQL和客户端有没关系
    因为涉及用数据集到循环赋值
      

  3.   

    Create Table T
    (
    name varchar(10),
    Age  int
    )
     
    insert into t values('张三', 1)
    insert into t values('李四', 5)
    insert into t values('王五', 6) 
     Select  T.*  From T inner join
     (
    Select   CAST( '<v>'+REPLACE('张三,张三,李四,张三,李四,张三',',','</v><v>')+'</v>' as xml) As xml   
     ) a outer apply ( Select x.y.value('.','varchar(100)') as val 
    From a.xml.nodes('/v') x(y)) b
    on T.name=b.val --Where in 是不行了,改成这样看行不行 
      

  4.   

    应该是不行的,Where in之后就剩下两条记录了,无法按要求显示结果,除非在拼SQL语句时增加大量语句来实现。