我正在尝试更改一组列中的美元金额
我尝试了几种WHEN和THEN组合
我可以使用dbo.cards中的select来选择我需要的所有行。然后从这些行开始,有一列称为“ RecurringBillingAmount”,我现在尝试将“ RecurringBillingAmount”列中的值从29.98更改为34.98
select * from dbo.cards WHERE productcode = '2x $19.99 SUBSCRIPTI'
WHEN RecurringBillingAmount = '29.98' THEN '34.98'
答案 0 :(得分:3)
尝试一下:
select *,
case WHEN RecurringBillingAmount = '29.98'
THEN '34.98'
end as new_amount
from dbo.cards WHERE productcode = '2x $19.99 SUBSCRIPTI'
这会将一列添加到您的输出中。
由于您要使用新列替换旧列,因此请不要在select语句中包括旧列。
答案 1 :(得分:1)
这是您要找的吗?假设您要更新表,而不仅仅是在查询结果中显示更改。
UPDATE dbo.cards
SET RecurringBillingAmount = '34.98'
WHERE
productcode = '2x $19.99 SUBSCRIPTI'
AND
RecurringBillingAmount = '29.98';
答案 2 :(得分:0)
尝试一下...
SELECT
CASE
WHEN RecurringBillingAmount = '29.98' THEN '34.98'
ELSE RecurringBillingAmount
END RecurringBillingAmount
FROM dbo.cards
WHERE productcode = '2x $19.99 SUBSCRIPTI'