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個字符。 –
一個好的提示是始終格式化您的代碼。與您的文字一樣,大塊文字難以閱讀。這阻止人們幫助你。 **編輯**複製/粘貼失敗導致我提供有關表名稱的不正確建議。抱歉。 –