这样输出来的是空字符串 create table #a (name varchar(100))
insert into #a values ('饮食男女')
insert into #a values ('a')Declare @strTemp varchar(100)Select @strTemp='''饮食男女'',''笑话'''exec('select * from #a where name in ('+@strTemp+')')drop table #a

解决方案 »

  1.   

    Declare @strTemp varchar(100)Select @strTemp='''饮食男女'',''笑话'''exec('Declare cu_Temp Cursor For Select jm_Name From Data_Path Where jm_Name In ('+@strTemp+')')Open cu_TempSelect @strTemp=''Fetch Next From cu_Temp Into @strTemp
    Select @strTemp   Close cu_Temp
    DealLocate cu_Temp
      

  2.   

    Declare @strTemp varchar(100)Select @strTemp='''饮食男女'',''笑话'''exec('Declare cu_Temp Cursor For Select jm_Name From Data_Path Where jm_Name In ('+@strTemp+')')Open cu_TempSelect @strTemp=''Fetch Next From cu_Temp Into @strTemp
    Select @strTempClose cu_Temp
    DealLocate cu_Temp
      

  3.   

    Declare @strTemp varchar(100)Select @strTemp='''饮食男女'',''笑话'''exec('Declare cu_Temp Cursor For Select jm_Name From Data_Path Where jm_Name In ('+@strTemp+')')Open cu_TempSelect @strTemp=''Fetch Next From cu_Temp Into @strTemp
    Select @strTemp   Close cu_Temp
    DealLocate cu_Temp
      

  4.   

    改为这样:create table #a (name varchar(100))
    insert into #a values ('饮食男女')
    insert into #a values ('a')
    Declare @strTemp varchar(100)
    Select @strTemp='''饮食男女'',''笑话'''
    --exec('select * from #a where name in ('+@strTemp+')')
    exec('Declare cu_Temp Cursor For Select name From #a Where name In ('+@strTemp+')')
    Open cu_Temp
    Select @strTemp=''
    Fetch Next From cu_Temp Into @strTemp
    while @@Fetch_Status<>-1
    begin
    Select @strTemp
    Fetch Next From cu_Temp Into @strTemp
    end
    Close cu_Temp
    DealLocate cu_Temp
    drop table #a结果:饮食男女
      

  5.   

    in后面不能直接使用变量。
    可以按照大力的方式,使用动态SQL执行。