declare @g_Condi2 varchar(1000)
set @g_Condi2= 'and State = ''在职'''
select  name,sex,address,photo,state from t_name
where name='张三'+@G_Condi2
为什么不能执行?应该怎样解决.

解决方案 »

  1.   

    declare @g_Condi2 varchar(1000)
    set @g_Condi2= 'and State = ''在职'''
    exec('select name,sex,address,photo,state from t_name
    where name=''张三'''+@G_Condi2+'');
      

  2.   

    我也是hongqi162(失踪的月亮)这样做,但通过存储过程调用,不能返回查询结果集给调用方.
      

  3.   


    declare @g_Condi2 varchar(1000)
    set @g_Condi2= 'and State = ''在职'''
    create table #test
    (name varchar(10),
    sex bit,
    address varchar(100),
    photo image,
    state bit
    )insert into #test
    exec('select name,sex,address,photo,state from t_name
    where name=''张三'''+@G_Condi2+'');select * from #test