Неизвестное исключение Sql (Number = 102, Message = Неверный синтаксис рядом с ','.) - PullRequest
0 голосов
/ 07 октября 2019

Я получил эту синтаксическую ошибку рядом с ','

Я уже пробовал некоторые решения, так как этот вопрос уже задавался на этом форуме ранее, но безрезультатно.

string sqlSelect = "SELECT"
+ " 'RI' AS DocType, DebtorCode, DocNo, DocDate, [Description]"
+ ",SalesAgent, LocalNetTotal AS LocalAmount,"
+ "(Outstanding * CurrencyRate) AS LocalBalance"
+ " FROM ARINVOICE"
+ " WHERE Cancelled = 'F'"
+ " UNION"
+ " SELECT 'RD' AS DocType, DebtorCode, DocNo, DocDate, [Description]"
+ ",SalesAgent, LocalNetTotal AS LocalAmount"
+ ",Outstanding AS LocalBalance"
+ " FROM ARDN"
+ " WHERE Cancelled = 'F'"
+ " UNION"
+ " SELECT 'RC' AS DocType, DebtorCode, DocNo, DocDate, [Description]"
+ ",'' AS SalesAgent, LocalNetTotal AS LocalAmount"
+ ",(NetTotal - KnockOffAmt + RefundAmt) * CurrencyRate AS LocalBalance"
+ " FROM ARCN"
+ " WHERE Cancelled = 'F'"
+ " UNION"
+ " SELECT 'RP' AS 'DocType', 'DebtorCode', 'DocNo', 'DocDate', 
[Description]"
+ ",'' AS SalesAgent, LocalPaymentAmt AS LocalAmount"
+ ",LocalUnappliedAmount AS LocalBalance"
+ " FROM ARPAYMENT"
+ " WHERE Cancelled = 'F'";

Является ли ихчто-то не так с моим запросом? Потому что я уже проверил это в течение 2 дней и не смог найти никаких ошибок, не то чтобы я знал. Надеюсь, что кто-нибудь может помочь.

Ответы [ 2 ]

1 голос
/ 07 октября 2019

вы пытались удалить DocType?

string sqlSelect = "SELECT"
+ " 'RI' AS DocType, DebtorCode, DocNo, DocDate, [Description]"
+ ",SalesAgent, LocalNetTotal AS LocalAmount,"
+ "(Outstanding * CurrencyRate) AS LocalBalance"
+ " FROM ARINVOICE"
+ " WHERE Cancelled = 'F'"
+ " UNION"
+ " SELECT 'RD' AS DocType, DebtorCode, DocNo, DocDate, [Description]"
+ ",SalesAgent, LocalNetTotal AS LocalAmount"
+ ",Outstanding AS LocalBalance"
+ " FROM ARDN"
+ " WHERE Cancelled = 'F'"
+ " UNION"
+ " SELECT 'RC' AS DocType, DebtorCode, DocNo, DocDate, [Description]"
+ ",'' AS SalesAgent, LocalNetTotal AS LocalAmount"
+ ",(NetTotal - KnockOffAmt + RefundAmt) * CurrencyRate AS LocalBalance"
+ " FROM ARCN"
+ " WHERE Cancelled = 'F'"
+ " UNION"
+ " SELECT 'RP' AS DocType, DebtorCode, DocNo, DocDate, 
[Description]"
+ ",'' AS SalesAgent, LocalPaymentAmt AS LocalAmount"
+ ",LocalUnappliedAmount AS LocalBalance"
+ " FROM ARPAYMENT"
+ " WHERE Cancelled = 'F'";
0 голосов
/ 07 октября 2019

В SQL SERVER, проверьте ниже скрипт-

declare @sqlSelect nvarchar(max)
select @sqlSelect = N' 
SELECT ''RI'' AS DocType,DebtorCode,DocNo,DocDate,[Description],SalesAgent,LocalNetTotal AS LocalAmount,
(Outstanding * CurrencyRate) AS LocalBalance 
FROM ARINVOICE WHERE Cancelled = ''F''
UNION
SELECT ''RD'' AS DocType,DebtorCode,DocNo,DocDate,[Description],SalesAgent,LocalNetTotal AS LocalAmount,Outstanding AS LocalBalance
FROM ARDN WHERE Cancelled = ''F''
UNION
SELECT ''RC'' AS DocType,DebtorCode,DocNo,DocDate,[Description],'''' AS SalesAgent,LocalNetTotal AS LocalAmount,
((NetTotal - KnockOffAmt + RefundAmt) * CurrencyRate) AS LocalBalance
FROM ARCN WHERE Cancelled = ''F''
UNION
SELECT ''RP'' AS DocType,DebtorCode,DocNo,DocDate,[Description],'''' AS SalesAgent,LocalPaymentAmt AS LocalAmount,
LocalUnappliedAmount AS LocalBalance
FROM ARPAYMENT WHERE Cancelled = ''F'' '

print (@sqlSelect)

--exec (@sqlSelect)
...