我有一個名為 的 SQL 表Response_Master_Incident
,我想將昨天的資料復制到 CSV 檔案中。包含日期的欄位稱為Response_Date
。這是日期時間格式YYYY-MM-DD 00:00:00.000
。我寫了以下內容:
SQLCMD -S cadarchive -d Reporting_System -E -Q "Select ID,Master_Incident_Number,Response_Date,Problem,MethodOfCallRcvd,EMD_Used,Determinant,ProQa_CaseNumber,ProQa_CaseNumber_Fire,ProQa_CaseNumber_Police,MachineName,CallTaking_Performed_By FROM [Response_Master_Incident] where [Response_Date]>=cast(dateadd(day,-1, CURRENT_TIMESTAMP) as date)
and [Response_Date] < cast(current_timestamp as date) and EMD_Used=1" -s "," -o "C:\ProQASQL\Exported_Table.csv"
@pause
但是當我運行它時,我得到了錯誤:
C:\ProQASql>and [Response_Date] as date) and EMD_Used=1" -s "," -o "C:\ProQASQL\Exported_Table.csv" 0<cast(current_timestamp
The system cannot find the file specified."
有人可以指出我做錯了什么嗎?
如果我洗掉有關日期的子句并將其保留為Where EMD_Used=1
,則 bat 檔案將正確運行。
uj5u.com熱心網友回復:
我通過使用以下方法解決了這個問題:
SQLCMD -S cadarchive -d Reporting_System -E -Q "select ID,Master_Incident_Number,Response_Date,Problem,MethodOfCallRcvd,EMD_Used,Determinant,ProQa_CaseNumber,ProQa_CaseNumber_Fire,ProQa_CaseNumber_Police,MachineName,CallTaking_Performed_By FROM [Response_Master_Incident] WHERE CONVERT(date, Response_Date) = DATEADD(day, -1, CONVERT(date, getdate())) and EMD_Used=1" -s "," -o "C:\ProQASQL\Exported_Table.csv"
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/529341.html
標籤:批处理文件