小弟需要在a表里查询姓名字段,但字段内容是_bstr_t变量,请问下面的写法有问题吗??
select * from a where 姓名="+xingming+",

解决方案 »

  1.   

    select * from a where 姓名=@name
      

  2.   

    exec('select * from tb where '+@字段变量+'=xxx')
      

  3.   

    有点迷。。
    是select * from a where 姓名="+@xingming+"么??
      

  4.   

    LZ SQL 基础有点差,去学校学一下吧:
    http://www.w3school.com.cn
      

  5.   

    declare @xingming varchar(50)
    set @xingming='aaa'
    select * from a where 姓名=@xingming
      

  6.   

    你这个应该是在程序中传入的变量吧?先把_bstr_t付一个变量名,假设为@name,然后把_bstr_t的值传到@name中,再
    select * from a where 姓名=@name即可。