我在將變量加工到現有代碼片段時遇到問題。我確定它很簡單,但我沒有得到任何答案。包含附加變量的C#命令
這是當前代碼,這沒有錯誤:
new SqlCommand(@"xp_cmdshell 'bcp ""SELECT tipReportingSummaryView.payGroupCode, employee.employeeFName + '' '' + employee.employeeLName AS employeeName, tipReportingSummaryView.employeeID, SUM(tipReportingSummaryView.netChargeTips) AS netChargeTips, tipReportingSummaryView.positionCode, rvc.rvcName, ''CHG TIPS'' AS tipType FROM tipReportingSummaryView INNER JOIN employee ON tipReportingSummaryView.employeeID = employee.employeeID INNER JOIN rvc ON tipReportingSummaryView.rvcID = rvc.rvcID WHERE (tipReportingSummaryView.businessDate >= (dateadd(day,(-15),datediff(day,(0),getdate())))) AND (tipReportingSummaryView.businessDate <= (dateadd)) AND (tipReportingSummaryView.payGroupCode = 1) GROUP BY tipReportingSummaryView.payGroupCode, employee.employeeFName + employee.employeeLName, tipReportingSummaryView.employeeID, tipReportingSummaryView.positionCode, rvc.rvcName, employee.employeeFName + '' '' + employee.employeeLName HAVING SUM(tipReportingSummaryView.netChargeTips) <> 0"" queryout " + filePath + " -U sa -P password -c -t ,'", conn))
我想要(tipReportingSummaryView.payGroupCode =),以等於payGroup變量的值,所以是這樣的:
new SqlCommand(@"xp_cmdshell 'bcp ""SELECT tipReportingSummaryView.payGroupCode, employee.employeeFName + '' '' + employee.employeeLName AS employeeName, tipReportingSummaryView.employeeID, SUM(tipReportingSummaryView.netChargeTips) AS netChargeTips, tipReportingSummaryView.positionCode, rvc.rvcName, ''CHG TIPS'' AS tipType FROM tipReportingSummaryView INNER JOIN employee ON tipReportingSummaryView.employeeID = employee.employeeID INNER JOIN rvc ON tipReportingSummaryView.rvcID = rvc.rvcID WHERE (tipReportingSummaryView.businessDate >= (dateadd(day,(-15),datediff(day,(0),getdate())))) AND (tipReportingSummaryView.businessDate <= (dateadd)) AND (tipReportingSummaryView.payGroupCode = " + payGroup + ") GROUP BY tipReportingSummaryView.payGroupCode, employee.employeeFName + employee.employeeLName, tipReportingSummaryView.employeeID, tipReportingSummaryView.positionCode, rvc.rvcName, employee.employeeFName + '' '' + employee.employeeLName HAVING SUM(tipReportingSummaryView.netChargeTips) <> 0"" queryout " + filePath + " -U sa -P password -c -t ,'", conn))
摘要版
電流:
(tipReportingSummaryView.payGroupCode =1)
期望:
(tipReportingSummaryView.payGroupCode = " + payGroup + ")
通過添加「+ payGroup +」,我得到在該行各類語法錯誤,所以它顯然使其彈了出來。
歡迎任何建議。
我覺得payGroup是一個局部變量,他希望它的值在字符串中。 – crashmstr
您可能想要發佈您獲得的特定語法錯誤。 – crashmstr
@crashmstr - 是的,這個數字(刪除以前的評論,以防止任何混淆) – VisualMelon