大胆猜想:楼主在动态生成sql语句
select * from tbl_cx where 1=1 and birthday >= '2001-05-12'and lasttime <= '2004-08-09'

解决方案 »

  1.   

    关键就在于怎么区分哪个AND是你想换的,哪个是想留下的。然后构造正则表达式就很高效
      

  2.   

    可以使用Stuff来替换SELECT STUFF('abcdef', 2, 3, '')
      

  3.   

    不如条件后加1=1,这样不用管and了where 1=1 ...
      

  4.   

    select stuff('select * from tbl_cx where  and birthday >= ''2001-05-12''and lasttime <= ''2004-08-09''',patindex('%where%','select * from tbl_cx where  and birthday >= ''2001-05-12''and lasttime <= ''2004-08-09''')+5,0,' 1=1 ')
      

  5.   

    因为我这个语句前面的字符个数是固定的,所以上面的 Stuff 满足我的要求了