我有这样的代码:
Select
C.ClientId
,K.NameShort
,C.SetId
,C.CaseId
,C.ClientCaseNumber
,D.Name
,Pay.Overpayment
from CaseDetails as C
where (C.ClientId = @ClientId or @ClientId IS NULL) and (C.SetId = @SetId or @SetId IS NULL)
join Client as K on C.ClientId = K.ClientId
join DocumentDetails as DD on C.CaseDetailsId = DD.CaseDetailsId
join PaymentDocumentHistory as Pay on DD.DocumentId = Pay.DocumentId
join DebtorDetails as D on C.CaseDetailsId = D.CaseDetailsId
在尝试运行它时,它给出了关于'join'附近的错误语法的错误。不幸的是,我不知道为什么会出现这样的错误..
答案 0 :(得分:7)
JOIN
是FROM
子句的一部分。 WHERE
子句位于(整个)FROM
子句之后。
Select
C.ClientId
,K.NameShort
,C.SetId
,C.CaseId
,C.ClientCaseNumber
,D.Name
,Pay.Overpayment
from CaseDetails as C
join Client as K on C.ClientId = K.ClientId
join DocumentDetails as DD on C.CaseDetailsId = DD.CaseDetailsId
join PaymentDocumentHistory as Pay on DD.DocumentId = Pay.DocumentId
join DebtorDetails as D on C.CaseDetailsId = D.CaseDetailsId
where (C.ClientId = @ClientId or @ClientId IS NULL) and (C.SetId = @SetId or @SetId IS NULL)
答案 1 :(得分:1)
join
出现在where
之前。
from CaseDetails as C
join Client as K on C.ClientId = K.ClientId
join DocumentDetails as DD on C.CaseDetailsId = DD.CaseDetailsId
join PaymentDocumentHistory as Pay on DD.DocumentId = Pay.DocumentId
join DebtorDetails as D on C.CaseDetailsId = D.CaseDetailsId
where (C.ClientId = @ClientId or @ClientId IS NULL) and (C.SetId = @SetId or @SetId IS NULL)
答案 2 :(得分:0)
你的JOINS不合适。你已经把你的JOIN放在了WHERE子句之后。
Select C.ClientId
,K.NameShort
,C.SetId
,C.CaseId
,C.ClientCaseNumber
,D.Name
,Pay.Overpayment
from CaseDetails as C
join Client as K on C.ClientId = K.ClientId
join DocumentDetails as DD on C.CaseDetailsId = DD.CaseDetailsId
join PaymentDocumentHistory as Pay on DD.DocumentId = Pay.DocumentId
join DebtorDetails as D on C.CaseDetailsId = D.CaseDetailsId
where (C.ClientId = @ClientId or @ClientId IS NULL) and (C.SetId = @SetId or @SetId IS NULL)