NetSuite SQL的情况何时

时间:2016-12-22 00:44:14

标签: sql netsuite

我正在尝试在NetSuite保存的搜索中编写SQL查询,如果满足某些条件,则返回文本值,如果不满足,则移动到下一个CASE WHEN语句。这就是我所拥有的:L

CASE WHEN {shipstate} IN ('AK','ID','MT','OR','WA') THEN 'Northwest' 
ELSE CASE WHEN {shipstate} IN ('CA','HI','NV','AZ') THEN 'West' 
ELSE CASE WHEN {shipstate} IN ('CO','NM','UT','WY') THEN 'Rockies' 
ELSE CASE WHEN {shipstate} IN ('AR','KS,'LA','OK','TX') THEN 'SO Central' 
ELSE CASE WHEN {shipstate} IN ('IN','KY','MI','OH') THEN 'Great Lakes' 
ELSE CASE WHEN {shipstate} IN ('IA','IL','MN','MO','NE','ND','SD','WI') THEN 'Midwest' 
ELSE CASE WHEN {shipstate} IN ('CT','MA','ME','NH','RI','VT') THEN 'Northeast' 
ELSE 'Southeast' 
END END END END END END END

我不确定我是否将ENDS插入错误的位置,但我之前确实使用了2个CASE WHEN语句。任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:5)

您可以在案例陈述中使用多个when条款,因此您只需要一个case和一个end,如下所示:

CASE 
    WHEN {shipstate} IN (
        'AK','ID','MT','OR','WA'
        ) THEN 'Northwest' 
    WHEN {shipstate} IN (
        'CA','HI','NV','AZ'
        ) THEN 'West' 
    WHEN {shipstate} IN (
        'CO','NM','UT','WY'
        ) THEN 'Rockies' 
    WHEN {shipstate} IN (
        'AR','KS','LA','OK','TX'
        ) THEN 'SO Central' 
    WHEN {shipstate} IN (
        'IN','KY','MI','OH'
        ) THEN 'Great Lakes' 
    WHEN {shipstate} IN (
        'IA','IL','MN','MO','NE','ND','SD','WI'
        ) THEN 'Midwest' 
    WHEN {shipstate} IN (
        'CT','MA','ME','NH','RI','VT'
        ) THEN 'Northeast' 
    ELSE 'Southeast' 
END

顺便说一句,您忘记了'条件中的IN