我尝试返回“增加的调整”或“减少的调整”,这取决于“金额”列中的值是正数还是负数。
CASE amount
when amount > 0 then "Increase Adjustment"
when amount < 0 then "Decreased Adjustment"
else "ERROR"
end as
transaction_type
任何建议都将不胜感激……
编辑:整个select=:
select
tx_date,
bank_account,
description,
amount,
currency,
CASE bank_account
when 'CAD-FTX' then 'Suspense_CAD'
when 'USD-PRO' then 'Suspense_USD'
when 'CAD-PRO' then 'Suspense_CAD'
when 'USD-ALL' then 'Suspense_USD'
when 'TD-USA' then 'Suspense_USD'
end
suspense_account,
CASE amount
when cast(amount as float) > 0 then "Increase Adjustment"
when cast(amount as float) < 0 then "Decreased Adjustment"
end
transaction_type
from [sys_tx_combined]
发布于 2018-05-25 20:08:50
这样如何:
CASE
when amount > 0 then "Increase Adjustment"
when amount < 0 then "Decreased Adjustment"
else "ERROR"
end as
transaction_type
发布于 2018-05-25 20:09:36
因为您的语句开头是
CASE amount
您指定的是一个简单的CASE表达式,而不是amount,这意味着WHEN子句只能是相等检查。尝试搜索表达式:
CASE
when amount > 0 then "Increase Adjustment"
when amount < 0 then "Decreased Adjustment"
else "ERROR"
end as
transaction_type
更多信息:https://docs.microsoft.com/en-us/sql/t-sql/language-elements/case-transact-sql?view=sql-server-2017
发布于 2018-05-25 20:12:39
CASE
when amount > '0' then "Increased Adjustment"
when amount < '0' then "Decreased Adjustment"
else "ERROR"
end as
transaction_type
https://stackoverflow.com/questions/50536160
复制相似问题