0
时,这是我的查询:SQL查询错误转换CSV文件
DECLARE @cmd VARCHAR(255)
SET @cmd = 'bcp "select Cash.TransC_dtmDateTime, case
when CONVERT(varchar(10),Cash.TransC_dtmDateTime,108) <'06.00' then (convert(varchar(10),Cash.TransC_dtmDateTime -1,103))
else
(convert(varchar(10),Cash.TransC_dtmDateTime,103))
end as TransDate, tblTrans_Ticket.TransT_intNoOfSeats as NoOfSeats into #seats FROM tblTrans_Cash Cash , tblTrans_Ticket , tblPaymentType
WHERE Cash.TransC_strType = tblPaymentType.PayType_strType and tblTrans_Ticket.TransT_lgnNumber= Cash.TransC_lgnNumber and
Cash.TransC_dtmDateTime between '2016-07-01 06:00:00.000' and '2016-08-01 06:00:00.000' and
tblTrans_Ticket.TransT_intNoOfSeats >0
and Cash.Workstation_strCode='K_DEDEDEDE'
and tblPaymentType.PayType_strDescription in ('JUSPAY','CITRUS','FUELWALLETONLINE','CREDIT CARD')
AND ISNULL(Cash.TransC_strBKCardNo,'') not like '990022%'
order by Cash.TransC_dtmDateTime
select (convert(varchar(10),TransDate,103)), sum(NoOfSeats)as seats from #seats group by convert(varchar(10),TransDate,103) order by TransDate
drop table #seats" queryout "c:/tests.csv" -U sa -P test -S 192.168.57.5,1441 -T -c -t,'
Exec xp_cmdshell @cmd
当我执行它,它显示了这个错误:
Msg 102, Level 15, State 1, Line 8
Incorrect syntax near '2016'
您需要[正确转义](https://www.google.com/search?q=sql+server+escape+quote)(嵌套)引号。另请注意[agmed abdelqader的答案](https://stackoverflow.com/questions/43340864/sql-query-error-when-converting-csv-file#comment73745120_43340864)。 – RobIII
增加'@ cmd'的长度,其值长度超过1000个字符。 –
一个好的提示是始终格式化您的代码。与您的文字一样,大块文字难以阅读。这阻止人们帮助你。 **编辑**复制/粘贴失败导致我提供有关表名称的不正确建议。抱歉。 –