-2
UPDATE [Table] SET [Table].[Rating] = 'A-'
WHERE ((([Table].[Field1])<>'No'
And     ([Table].[Field2])<>'No')
AND    (([Table].[Field3])<>'No')
AND    (([Table].[Field4])<>'No')


UPDATE [Table] SET [Table].[Rating] = 'B'
WHERE ((([Table].[Field1])<>'No'
And     ([Table].[Field2])<>'No')
AND    (([Table].[Field3])<>'No')
AND    (([Table].[Field4])='No')

UPDATE [Table] SET [Table].[Rating] = 'C'
WHERE ((([Table].[Field1])<>'No'
And     ([Table].[Field2])<>'No')
AND    (([Table].[Field3])='No')
AND    (([Table].[Field4])='No')

UPDATE [Table] SET [Table].[Rating] = 'D'
WHERE ((([Table].[Field1])<>'No'
And     ([Table].[Field2])='No')
AND    (([Table].[Field3])='No')
AND    (([Table].[Field4])='No')
4

3 回答 3

2

看看您是否可以使用UPDATE带有SwitchRating语句来根据您的条件分配值。

UPDATE [Table] AS t
SET t.[Rating] = 
    Switch
        (
            t.Field2 <> 'No' AND t.Field3 <> 'No' AND t.Field4 <> 'No', 'A',
            t.Field2 <> 'No' AND t.Field3 <> 'No' AND t.Field4 =  'No', 'B',
            t.Field2 <> 'No' AND t.Field3 =  'No' AND t.Field4 =  'No', 'C',
            t.Field2 =  'No' AND t.Field3 =  'No' AND t.Field4 =  'No', 'D'
        )
WHERE
        t.Field1 <> 'No';
于 2013-11-08T20:35:15.710 回答
1

是的,这个答案应该会有所帮助,使用临时表: 一个 SQL 语句中的多个更新

但是,我看不出您的 WHERE 子句在您更新到的 4 个值之间有任何差异。那是对的吗?

于 2013-11-08T20:29:42.830 回答
0

UPDATE Table SET Table.[Rating] = 'A-' WHERE (((Table.[Field1])<>'No' And (Table.[Field2]))<>'No') And ((Table.[Field3 ]))<>'No') 和 ((Table.[Field4])<>'No'));

于 2014-03-12T12:06:11.790 回答