Declare @temp varchar(100)select @temp='temp1'select count(*) from table_name
where field_name in (@temp)

解决方案 »

  1.   

    Declare @temp varchar(100)select @temp='''temp1'',''temp2'''exec('select count(*) from table_name where field_name in ('+@temp+')')
      

  2.   

    Declare @temp varchar(100)select @temp='temp1'exec('select count(*) from table_name
    where (field_name in '+@temp)
      

  3.   

    Declare @temp varchar(100),@sql varchar(200)select @temp='''temp1'',''temp2'''
    set @sql='select count(*) from table_name where (field_name in (' + @temp + '))'exec (@sql)