我的语法不正确:
SELECT
BA.Bank,
BA.AccountNo,
BA.closingBalance,
BT.TransactionDate =(Case When ClosingBalance <= 0 Then Getdate()
Else TransactionDate
End),
BankaccountID
FROM BankTransactionDetail BT Right Join dbo.BankAccount BA ON
BT.AccountID = BA.AccountID
获取错误:'='附近的语法不正确。
注意:没有加入其工作正常。 Plaese帮助。
答案 0 :(得分:1)
你想要这个
SELECT BK.BankCode,
BA.Bank,
BA.AccountNo,
BA.closingBalance,
Case When BA.ClosingBalance <= 0 Then Getdate() Else BT.TransactionDate End,
BankaccountID
FROM BankTransactionDetail BT Right Join dbo.BankAccount BA ON BT.AccountID = BA.AccountID
或
试试这个
SELECT BA.Bank,
BA.AccountNo,
BA.closingBalance,
TransactionDate =(Case When ClosingBalance <= 0 Then Getdate() Else TransactionDate End),
BankaccountID
FROM BankTransactionDetail BT Right Join dbo.BankAccount BA ON BT.AccountID = BA.AccountID
答案 1 :(得分:1)
定义别名列时不要使用表后缀。在您的情况下,您要获取&#39; TransactionDate&#39; 列,并尝试使用 BT 作为前缀。在您添加前缀的那一刻,SQL Server将尝试从BT表中读取该列,并且它认为您将派生列分配给现有列。只需删除BT前缀,它应该适合您。
SELECT BK.BankCode,
BA.Bank,
BA.AccountNo,
BA.closingBalance,
TransactionDate =(Case When ClosingBalance <= 0 Then Getdate()
Else TransactionDate
End),
BankaccountID
FROM BankTransactionDetail BT Right Join dbo.BankAccount BA ON
BT.AccountID = BA.AccountID
答案 2 :(得分:1)
使用此:
SELECT
BA.Bank,
BA.AccountNo,
BA.closingBalance,
(CASE WHEN ClosingBalance <= 0 THEN GETDATE()
ELSE TransactionDate
END) AS TransactionDate,
BankaccountID
FROM BankTransactionDetail BT Right Join dbo.BankAccount BA ON
BT.AccountID = BA.AccountID