保险评级政策sql iif声明

时间:2011-11-15 06:53:04

标签: sql ms-access ms-access-2007

我想产生以下结果:

Table:[0050 Fix No Hit].[Fix_No_Hit]
Policy Number:     Insurance Score:   Insurance Score Factor:
100                  500                     2.13
101                  720                     1.47
102                  815                     1.00
103                  900                     0.69

使用以下规则:

Table: Tier_InsuranceScore
Insurance Score Chart:                      Factor:                 
649 or below                           2.13
(i assume insurance score has to be greater than 0) 
650 to 699                             1.86
700 to 799                             1.47
800 to 849                             1.00
850 to 899                             0.82
900 or above                           0.69

这是我到目前为止所做的:

SELECT HWData.[Policy Number],
   [0050 Fix No Hit].[Fix_No_Hit],
   iif([0050 Fix No Hit].[Fix_No_Hit] <=649, 2.13, 0),
   iif([0050 Fix No Hit].[Fix_No_Hit] <=699, 1.86, 0),
   iif([0050 Fix No Hit].[Fix_No_Hit] <=799, 1.47, 0),
   iif([0050 Fix No Hit].[Fix_No_Hit] <=849, 1.00, 0),
   iif([0050 Fix No Hit].[Fix_No_Hit] <=899, 0.82, 0),
   iif([0050 Fix No Hit].[Fix_No_Hit] >=900, 0.69, 0)
FROM [0050 Fix No Hit];

我再一次

    2.13 0 0 0 0 0 for policy 100
and 0 0 1.47 0 0 0 for policy 101 

但我只想要一列作为结果。

1 个答案:

答案 0 :(得分:0)

您只需要嵌套iif()语句:

SELECT HWData.[Policy Number],
   [0050 Fix No Hit].[Fix_No_Hit],
   iif([0050 Fix No Hit].[Fix_No_Hit] <= 649, 2.13, 
   iif([0050 Fix No Hit].[Fix_No_Hit] <= 699, 1.86, 
   iif([0050 Fix No Hit].[Fix_No_Hit] <= 799, 1.47, 
   iif([0050 Fix No Hit].[Fix_No_Hit] <= 849, 1.00, 
   iif([0050 Fix No Hit].[Fix_No_Hit] <= 899, 0.82, 
   iif([0050 Fix No Hit].[Fix_No_Hit] >= 900, 0.69, 0))))))
FROM [0050 Fix No Hit];