我对这个 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 部分,但我无法解决具体在哪里。你能帮我吗?
对不起我的英语不好。