试试就知道了!declare @a varchar(20)
set @a='''1'',''2'''
select name from table1 where convert(varchar(50),id) in (@a)

解决方案 »

  1.   

    问题出在select Pid from table2 where id=1  的返回结果是 ''1','2''  前后各多了 一个 ' 符号,用于表明返回的一个字符串,现在是怎么能解决掉这两个多加的 ‘ 符号
      

  2.   

    select Pid from table2 where id=1  的返回结果是 ''1','2''楼上的,不知道你去测试了没有!
      

  3.   

    将 varchar 值 ''1','2'' 转换为数据类型为 int 的列时发生语法错误。
    --------这是sql给的前后两个‘  是隐含的 你用查询分析器查询,返回结果的时候看不到但是如果你引发系统错误 就会报给你
      

  4.   

    但是如果我直接写select name from table1 where convert(varchar(50),id) in ('1','2') 就可以出来结果
      

  5.   

    to:whzww(无家的猫) 
    将 varchar 值 ''1','2'' 转换为数据类型为 int 的列时发生语法错误。????我当然有测试的啊!
      

  6.   

    skyboy0720(飞)select name from table1 where convert(varchar(50),id) in (select Pid from table2 where id=1)
    这句 如果改成
    select name from table1 where id in (select Pid from table2 where id=1)
    运行,就会报错 :将 varchar 值 ''1','2'' 转换为数据类型为 int 的列时发生语法错误。
      

  7.   

    如果你那边不出错,那就是我的sqlserver坏了?
      

  8.   

    select name from table1 where charindex(convert(varchar(50),id),(select Pid from table2 where id=1))>0
      

  9.   

    哦,你说select name from table1 where id in (select Pid from table2 where id=1)
    这句啊
    当然会错啊,你还不明白啊??试试就知道了!declare @a varchar(20)
    set @a='''1'',''2'''
    select name from table1 where convert(varchar(50),id) in (@a)问题的所在如果in()里面的内容是动态的取得,就相当于你是用
    '1'(这里或者是1)=('1','2')整个表达式,当然没有结果,不知道你明白没!
      

  10.   

    select name from table1 where convert(varchar(50),id) in (select Pid from table2 where id=1)
    这句话有问题,你现在选的是Pid而Convert(varchar(50),id)却是id,这是两个不同的字段,当然没有你要值!
      

  11.   

    TO:shenen(真的愛你) 
    这样的返回结果会多两个 如果 pid 里面记录的是 '11','17'那么返回的结果是 
    1
    7
    11
    17
    四条数据
      

  12.   

    TO: skyboy0720(飞) 
    我知道问题出在这里
    select name from table1 where id in (select Pid from table2 where id=1)现在是有什么办法能解决这个
      

  13.   

    表二 [pid] 里面存放的是由多个表一[ID]字段值形成的字符串,
    现在要做的是,我在表二中选择一条记录,然后根据记录的 [PID] 值 查出所有的表一相关数据PS: 数据库是老板设计的,没办法更改,要不就不用这么麻烦了
        郁闷阿
      

  14.   

    真的爱你  的方法就可以啊select name from tabl1 where charindex(convert(varchar(50),id),(select Pid from tabl2 where id=1))>0
      

  15.   

    他的方法要改一下select name from tabl1 where charindex(''''+convert(varchar(50),id)+'''',(select Pid from tabl2 where id=1))>0
    要不就会多出首尾两个不匹配的
    谢谢各位了终于搞定 可以回家吃饭了 饿死俺也