【发布时间】:2015-04-07 16:39:27
【问题描述】:
错误:在“结算日期”或附近出现语法错误 第 4 行:如果结算日期 > '2015-01-01' ^ ********** 错误**********
错误:在“结算日期”或附近出现语法错误
SQL 状态:42601
字符:50
update "Recon".ship_error
set
if settlement_date > '2015-01-01'
then
shipping_fee = case
when shipping_zone = 'NA' and order_status !='return_completed' then 0
when shipping_zone = 'NATIONAL' and total_weight <= 0.5 and order_status !='return_completed' then -55
when shipping_zone = 'LOCAL' and total_weight <= 0.5 and order_status !='return_completed' then -29.4
when shipping_zone = 'ZONAL' and total_weight <= 0.5 and order_status !='return_completed' then -55
when shipping_zone = 'NA' and order_status !='return_completed' then 0
when shipping_zone = 'NATIONAL' and total_weight >= 0.5 and total_weight <= 1 and order_status !='return_completed' then -55
when shipping_zone = 'LOCAL' and total_weight >= 0.5 and total_weight <=1 order_status !='return_completed' then -29.4
when shipping_zone = 'ZONAL' and total_weight >= 0.5 and total_weight <=1 order_status !='return_completed' then -55
end
end
if settlement_date <= '2015-01-01'
then
when shipping_zone = 'NA' and order_status !='return_completed' then 0
when shipping_zone = 'NATIONAL' and total_weight <= 0.5 and order_status !='return_completed' then -43.4
when shipping_zone = 'LOCAL' and total_weight <= 0.5 and order_status !='return_completed' then -24.3
when shipping_zone = 'ZONAL' and total_weight <= 0.5 and order_status !='return_completed' then -43.4
when shipping_zone = 'NA' and order_status !='return_completed' then 0
when shipping_zone = 'NATIONAL' and total_weight >= 0.5 and total_weight <= 1 and order_status !='return_completed' then -86.8
when shipping_zone = 'LOCAL' and total_weight >= 0.5 and total_weight <=1 order_status !='return_completed' then -58.3
when shipping_zone = 'ZONAL' and total_weight >= 0.5 and total_weight <=1 order_status !='return_completed' then -86.8
end
end
from "Recon".ship_error;
或者我也试过这个代码
update "Recon".ship_error
set shipping_fee = case
when settlement_date > '2015-01-01'
then
--shipping_fee = case
when shipping_zone = 'NA' and order_status !='return_completed' then 0
when shipping_zone = 'NATIONAL' and total_weight <= 0.5 and order_status !='return_completed' then -55
when shipping_zone = 'LOCAL' and total_weight <= 0.5 and order_status !='return_completed' then -29.4
when shipping_zone = 'ZONAL' and total_weight <= 0.5 and order_status !='return_completed' then -55
when shipping_zone = 'NA' and order_status !='return_completed' then 0
when shipping_zone = 'NATIONAL' and total_weight >= 0.5 and total_weight <= 1 and order_status !='return_completed' then -55
when shipping_zone = 'LOCAL' and total_weight >= 0.5 and total_weight <=1 order_status !='return_completed' then -29.4
when shipping_zone = 'ZONAL' and total_weight >= 0.5 and total_weight <=1 order_status !='return_completed' then -55
end
end
when settlement_date <= '2015-01-01'
then
when shipping_zone = 'NA' and order_status !='return_completed' then 0
when shipping_zone = 'NATIONAL' and total_weight <= 0.5 and order_status !='return_completed' then -43.4
when shipping_zone = 'LOCAL' and total_weight <= 0.5 and order_status !='return_completed' then -24.3
when shipping_zone = 'ZONAL' and total_weight <= 0.5 and order_status !='return_completed' then -43.4
when shipping_zone = 'NA' and order_status !='return_completed' then 0
when shipping_zone = 'NATIONAL' and total_weight >= 0.5 and total_weight <= 1 and order_status !='return_completed' then -86.8
when shipping_zone = 'LOCAL' and total_weight >= 0.5 and total_weight <=1 order_status !='return_completed' then -58.3
when shipping_zone = 'ZONAL' and total_weight >= 0.5 and total_weight <=1 order_status !='return_completed' then -86.8
end
end
from "Recon".ship_error;
【问题讨论】:
-
是有问题还是您只是为了娱乐而发布随机错误消息?
-
PostgreSQL 不支持
if子句。不过,您可以使用嵌套的CASE子句。 -
我也试过嵌套的 case 子句@SimoKivistö
标签: postgresql-9.1