我无法将变量处理到现有代码片段中。我敢肯定,我缺少一些简单的东西,但是我什么也没有。
这是当前代码,没有错误:
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 +”,我在该行上得到了各种语法错误,所以它显然导致它被炸毁。
欢迎任何建议。