我有一些SQL代码我在控制台应用程序中执行。它在扔:
" system.Data.SqlClient.SqlException:'附近的语法不正确 关键字' TB'。'
我尝试多次更改代码以使其正常工作,但它仍然会抛出相同的错误。通过尝试解决它,我已经发现了最后一个" TB"第二行到最后一行是错误的原因,它表示")TB"。有没有人知道为什么它不喜欢那里的结核病?这是代码:
string SQLCode = "SELECT TB.RowType,TB.company,TB.Account,TB.segvalue1,TB.segvalue2,TB.segvalue3,TB.segvalue4,TB.fiscalyear,TB.fiscalperiod,SUM(TB.BalanceAmt) as tbBalanceAmt" +
"FROM(SELECT 'Actual' AS RowType,GLJ.company,GLJ.glaccount AS Account,GLJ.segvalue1,GLJ.segvalue2,GLJ.segvalue3,GLJ.SegValue4," +
"GLJ.fiscalyear,GLJ.fiscalperiod,GLJ.jedate,GLJ.description,GLJ.vendornum,GLJ.apinvoicenum,SUM(GLJ.debitamount - GLJ.creditamount) as glBalanceAmt,"+
"GLJ.groupid,GLJ.posteddate FROM GLJrnDtl GLJ GROUP BY GLJ.company,GLJ.glaccount,GLJ.segvalue1,GLJ.segvalue2,GLJ.segvalue3,"+
"GLJ.SegValue4,GLJ.fiscalyear,GLJ.fiscalperiod,GLJ.jedate,GLJ.description,GLJ.vendornum,GLJ.apinvoicenum,GLJ.groupid,GLJ.posteddate"+
" UNION ALL SELECT 'Budget' AS RowType,GLB.company,GLB.BalanceAcct AS Account,GLB.segvalue1,GLB.segvalue2,GLB.segvalue3,GLB.segvalue4,GLB.fiscalyear,GLB.fiscalperiod,"+
"GLB.Date01 AS jedate,'' AS description,'' AS vendornum,'' AS apinvoicenum,SUM(GLB.BudgetAmt) as gbBalanceAmt,'' AS groupid,"+
"0 AS posteddate FROM GLBudgetDtl GLB WHERE GLB.segvalue3 <> '' AND GLB.BalanceType = 'D'"+
"GROUP BY GLB.company,GLB.BalanceAcct,GLB.segvalue1,GLB.segvalue2,GLB.segvalue3,GLB.segvalue4,GLB.fiscalyear,GLB.fiscalperiod,GLB.Date01, GLB.BudgetAmt) TB"+
" WHERE tb.Company = NVV AND TB.fiscalyear = '2017' AND tb.fiscalperiod BETWEEN 1 AND 10 and tb.segvalue1 = '4450'";
答案 0 :(得分:3)
字符串末尾没有空格。这意味着
tbBalanceAmt" + "FROM
评估为thBalanceAmtFrom
。