EXEC master..xp_cmdshell 'bcp "Select * from cnpl_feedback..cnplsheet where zipcode=214000 
and convert(char(10),sheetDate,20)>'2006-06-28' " queryout d:\DTssd.txt -c -S127.0.0.1 -Usa -P123456'
我需要将日期判断“2006-06-28”加上单引号,总是报错怎么办?
因为语句中已经有了单引号。
----------------------------------------

解决方案 »

  1.   

    convert(char(10),sheetDate,20)>''2006-06-28''
    换成两个单引试试
      

  2.   

    加单引号'2006-06-28'后:
    服务器: 消息 170,级别 15,状态 1,行 2
    第 2 行: '2006' 附近有语法错误。
    加2个单引号'2006-06-28'后:
    用法:  bcp {dbtable | query} {in | out | queryout | format} datafile
      [-m maxerrors]            [-f formatfile]          [-e errfile]
      [-F firstrow]             [-L lastrow]             [-b batchsize]
      [-n native type]          [-c character type]      [-w wide character type]
      [-N keep non-text native] [-V file format version] [-q quoted identifier]
      [-C code page specifier]  [-t field terminator]    [-r row terminator]
      [-i inputfile]            [-o outfile]             [-a packetsize]
      [-S server name]          [-U username]            [-P password]
      [-T trusted connection]   [-v version]             [-R regional enable]
      [-k keep null values]     [-E keep identity values]
      [-h "load hints"]
    NULL
      

  3.   

    LZ,我试了一下,不需要用convert就可以查出日期范围
    ----------------------------------
    EXEC master..xp_cmdshell 'bcp "Select * from 库名..syslogdate where indate>2006-06-28" queryout d:\DTssd.txt -c -S127.0.0.1 -Usa -P123456'
      

  4.   

    谢谢,去掉convert可以
    谢谢,加2个单引号也可以了