この T-SQL コードに問題があります。
SELECT
DQ.Code as DQ_Code, II.OrdNumber AS Cislo, II.Id As ID,
convert(varchar(10), cast(II.DocDate$DATE as datetime), 104) as DatumPlneni,
convert(varchar(10), cast(II.DueDate$DATE as datetime), 104) as DatumSplatnosti,
F.Name as Firma, F.ID as FIRMID,
(II.LocalAmount - II.LocalCreditAmount) as LocalAmount,
(II.LocalPaidAmount) as LocalPaidAmount,
(II.LocalAmount - II.LocalCreditAmount - II.LocalPaidAmount + II.LocalPaidCreditAmount) as LocalNotPaidAmount,
case
when
((case
when len(convert(varchar(10), cast(II.DueDate$DATE as datetime), 104) )=10
then convert(varchar(10), cast(II.DueDate$DATE as datetime), 104)
when ((len(convert(varchar(10), cast(II.DueDate$DATE as datetime), 104) )=9) and (substring(convert(varchar(10), cast(II.DueDate$DATE as datetime), 104) from 7 for 1) ='-'))
then substring(convert(varchar(10), cast(II.DueDate$DATE as datetime), 104) from 1 for 5)||'0'||substring(convert(varchar(10), cast(II.DueDate$DATE as datetime), 104) from 6 for 10)
when ((len(convert(varchar(10), cast(II.DueDate$DATE as datetime), 104) )=9) and (substring(convert(varchar(10), cast(II.DueDate$DATE as datetime), 104) from 7 for 1)<>'-'))
then substring(convert(varchar(10), cast(II.DueDate$DATE as datetime), 104) from 1 for 8)||'0'||substring(convert(varchar(10), cast(II.DueDate$DATE as datetime), 104) from 9 for 10)
when len(convert(varchar(10), cast(II.DueDate$DATE as datetime), 104) )=8
then substring(convert(varchar(10), cast(II.DueDate$DATE as datetime), 104) from 1 for 5)||'0'||substring(convert(varchar(10), cast(II.DueDate$DATE as datetime), 104) from 6 for 2) ||'0'||substring(convert(varchar(10), cast(II.DueDate$DATE as datetime), 104) from 8 for 2)
end) < cast(current_date as varchar(10))
)
then II.LocalAmount - II.LocalCreditAmount - II.LocalPaidAmount + II.LocalPaidCreditAmount
when
((case
when len(convert(varchar(10), cast(II.DueDate$DATE as datetime), 104) )=10
then convert(varchar(10), cast(II.DueDate$DATE as datetime), 104)
when ((len(convert(varchar(10), cast(II.DueDate$DATE as datetime), 104) )=9) and (substring(convert(varchar(10), cast(II.DueDate$DATE as datetime), 104) from 7 for 1) ='-'))
then substring(convert(varchar(10), cast(II.DueDate$DATE as datetime), 104) from 1 for 5)||'0'||substring(convert(varchar(10), cast(II.DueDate$DATE as datetime), 104) from 6 for 10)
when ((len(convert(varchar(10), cast(II.DueDate$DATE as datetime), 104) )=9) and (substring(convert(varchar(10), cast(II.DueDate$DATE as datetime), 104) from 7 for 1)<>'-'))
then substring(convert(varchar(10), cast(II.DueDate$DATE as datetime), 104) from 1 for 8)||'0'||substring(convert(varchar(10), cast(II.DueDate$DATE as datetime), 104) from 9 for 10)
when len(convert(varchar(10), cast(II.DueDate$DATE as datetime), 104) )=8
then substring(convert(varchar(10), cast(II.DueDate$DATE as datetime), 104) from 1 for 5)||'0'||substring(convert(varchar(10), cast(II.DueDate$DATE as datetime), 104) from 6 for 2) ||'0'||substring(convert(varchar(10), cast(II.DueDate$DATE as datetime), 104) from 8 for 2)
end) > cast(current_date as varchar(10))
)
then 0
end as NotPaidAfterDueD
FROM
IssuedInvoices II
LEFT JOIN DocQueues DQ ON DQ.ID=II.Docqueue_ID
LEFT JOIN Firms F ON F.ID=II.Firm_ID
WHERE
(II.LocalAmount - II.LocalCreditAmount - II.LocalPaidAmount + II.LocalPaidCreditAmount)>0
DBeaver で実行しようとすると、次のエラーが発生します。
SQL エラー [156] [S1000]: キーワード 'from' 付近の構文が正しくありません。
キーワード「from」付近の構文が正しくありません。
私の問題は CASE 部分にある可能性が最も高いですが、正確にどこを解決することはできません。誰か助けてくれませんか?
私の英語でごめんなさい。