@ToAirport varchar(50)select * from table where id in(@ToAirport)  我在程序调用时传入'2,3,5'参数,报错。
要怎么解决?

解决方案 »

  1.   

    select * from table where charindex(','+cast(id as varchar)+',',','+@ToAirport+',')>0
      

  2.   

    exec N'select * from table where id in(@ToAirport) '
      

  3.   


    --改用charindex
    Select * from [table] where CharIndex(',' + Cast(id As Varchar) + ',', ',' + @ToAirport + ',') > 0
      

  4.   

    或用charindex(','+left(id,10)+',',','+@ToAirport+',' )>0判断
      

  5.   

    --或者like
    Select * from [table] where ',' + @ToAirport + ',' Like '%,' + Cast(id As Varchar) + ',%'
      

  6.   

    晕了..
    总结一下:只能先拼语句后exec 对吗?
      

  7.   

    igelf(一知半解逛CN) ( ) 信誉:100  2007-08-17 16:42:24  得分: 0  
     
     
       晕了..
    总结一下:只能先拼语句后exec 对吗?
      
     
    ----------可以不用拼結語句的。就是改用charindex或者like。
    --改用charindex
    Select * from [table] where CharIndex(',' + Cast(id As Varchar) + ',', ',' + @ToAirport + ',') > 0--或者like
    Select * from [table] where ',' + @ToAirport + ',' Like '%,' + Cast(id As Varchar) + ',%'
      

  8.   

    30分这么多人抢..
    最后一问:为什么不能用in(@ToAirport) ?
      

  9.   

    igelf(一知半解逛CN) ( ) 信誉:100  2007-8-17 18:34:33  得分: 0  
     
     
       
    30分这么多人抢..
    最后一问:为什么不能用in(@ToAirport) ?  
    ---------------如果要用這種寫法,就使用動態SQL語句.