在MS Access中,我使用switch根据每行的ID更新列。这个SQL应该正常工作;但是,Access会返回“查询表达式中的表达式太复杂”。如果是这种情况,有没有办法解决或可能缩短此SQL以使其工作?
* note -1表示买方名称的第一个首字母出现在字母表中的M之前,0表示它是M,1表示它出现在M.之后。这只是另一个目的的测试。
Update AmazonCustomers SET Category = Switch(ID =1, -1, ID =2, 0, ID =3, -1, ID =4, -1, ID =5, -1, ID =6, -1, ID =7, 1, ID =8, -1, ID =9, -1, ID =10, -1, ID =11, -1, ID =12, 1, ID =13, 0, ID =14, -1, ID =15, -1, ID =16, -1, ID =17, 1, ID =18, -1, ID =19, 0, ID =20, 1, ID =21, -1, ID =22, -1, ID =23, -1, ID =24, -1, ID =25, -1, ID =26, -1, ID =27, -1, ID =28, -1, ID =29, 1, ID =30, 1, ID =31, 1, ID =32, -1, ID =33, -1, ID =34, 1, ID =35, -1, ID =36, 1, ID =37, -1, ID =38, -1, ID =39, -1, ID =40, 0, ID =41, 0, ID =42, 1, ID =43, -1, ID =44, -1, ID =45, -1, ID =46, 1, ID =47, -1, ID =48, 1, ID =49, -1, ID =50, 0, ID =51, -1, ID =52, 1, ID =53, -1, ID =54, -1, ID =55, 1, ID =56, 1, ID =57, 1, ID =58, -1, ID =59, 1, ID =60, -1, ID =61, -1, ID =62, 1, ID =63, -1, ID =64, -1, ID =65, -1, ID =66, 1, ID =67, -1, ID =68, 1, ID =69, 1, ID =70, -1, ID =71, 1, ID =72, -1, ID =73, -1, ID =74, -1, ID =75, -1, ID =76, 0, ID =77, 1, ID =78, 0, ID =79, 1, ID =80, -1, ID =81, -1, ID =82, 1, ID =83, -1, ID =84, 0, ID =85, -1, ID =86, 1, ID =87, -1, ID =88, -1, ID =89, -1, ID =90, -1, ID =91, -1, ID =92, 0, ID =93, -1, ID =94, -1, ID =95, -1, ID =96, -1, ID =97, -1, ID =98, -1, ID =99, 1, ID =100, -1, ID =101, 1, ID =102, 1, ID =103, -1, ID =104, 1, ID =105, -1, ID =106, 1, ID =107, -1, ID =108, 1, ID =109, 1, ID =110, 0, ID =111, -1, ID =112, -1, ID =113, 1, ID =114, 0, ID =115, -1, ID =116, -1, ID =117, 1, ID =118, 0, ID =119, 0, ID =120, -1, ID =121, 0, ID =122, 0, ID =123, 0, ID =124, -1, ID =125, 1, ID =126, -1, ID =127, 1, ID =128, -1, ID =129, -1, ID =130, -1, ID =131, -1, ID =132, -1, ID =133, -1, ID =134, 1, ID =135, -1, ID =136, -1, ID =137, -1, ID =138, -1, ID =139, -1, ID =140, -1, ID =141, -1, ID =142, -1, ID =143, 0, ID =144, -1, ID =145, -1, ID =146, -1, ID =147, 1, ID =148, -1, ID =149, 1, ID =150, -1, ID =151, 1, ID =152, -1, ID =153, 0, ID =154, -1, ID =155, -1, ID =156, -1, ID =157, -1);
谢谢!
答案 0 :(得分:3)
您是否可以将其作为单独的UPDATE语句运行? 如果是这样,您可以查询:
'Check if service exists and is running
Dim arrServices() As ServiceController = ServiceController.GetServices(machineName)
If Not arrServices.Any(Function(o) o.ServiceName = SERVICE_NAME) Then
' Service is missing...
Else
Dim oServiceController As New ServiceController(SERVICE_NAME, machineName)
If oServiceController.Status = ServiceControllerStatus.Running Then
' Service is running...
Else
' Service has stopped...
End If
End If
在IN语句中手动添加符合条件的数字。
答案 1 :(得分:1)
以下是使用单个连接的方法。
注意 - 如果您这样做了很多,请将值放在实际表中并加入到该表中。
Update AmazonCustomers (Category)
SELECT T.V
FROM AmazonCustomers
JOIN (
SELECT 1, -1
UNION ALL
SELECT 2, 0
UNION ALL
SELECT 3, -1
UNION ALL
SELECT 4, -1
UNION ALL
SELECT 5, -1
UNION ALL
SELECT 6, -1
UNION ALL
SELECT 7, 1
UNION ALL
SELECT 8, -1
UNION ALL
SELECT 9, -1
UNION ALL
SELECT 10, -1
UNION ALL
SELECT 11, -1
UNION ALL
SELECT 12, 1
UNION ALL
SELECT 13, 0
UNION ALL
SELECT 14, -1
UNION ALL
SELECT 15, -1
UNION ALL
SELECT 16, -1
UNION ALL
SELECT 17, 1
UNION ALL
SELECT 18, -1
UNION ALL
SELECT 19, 0
UNION ALL
SELECT 20, 1
UNION ALL
SELECT 21, -1
UNION ALL
SELECT 22, -1
UNION ALL
SELECT 23, -1
UNION ALL
SELECT 24, -1
UNION ALL
SELECT 25, -1
UNION ALL
SELECT 26, -1
UNION ALL
SELECT 27, -1
UNION ALL
SELECT 28, -1
UNION ALL
SELECT 29, 1
UNION ALL
SELECT 30, 1
UNION ALL
SELECT 31, 1
UNION ALL
SELECT 32, -1
UNION ALL
SELECT 33, -1
UNION ALL
SELECT 34, 1
UNION ALL
SELECT 35, -1
UNION ALL
SELECT 36, 1
UNION ALL
SELECT 37, -1
UNION ALL
SELECT 38, -1
UNION ALL
SELECT 39, -1
UNION ALL
SELECT 40, 0
UNION ALL
SELECT 41, 0
UNION ALL
SELECT 42, 1
UNION ALL
SELECT 43, -1
UNION ALL
SELECT 44, -1
UNION ALL
SELECT 45, -1
UNION ALL
SELECT 46, 1
UNION ALL
SELECT 47, -1
UNION ALL
SELECT 48, 1
UNION ALL
SELECT 49, -1
UNION ALL
SELECT 50, 0
UNION ALL
SELECT 51, -1
UNION ALL
SELECT 52, 1
UNION ALL
SELECT 53, -1
UNION ALL
SELECT 54, -1
UNION ALL
SELECT 55, 1
UNION ALL
SELECT 56, 1
UNION ALL
SELECT 57, 1
UNION ALL
SELECT 58, -1
UNION ALL
SELECT 59, 1
UNION ALL
SELECT 60, -1
UNION ALL
SELECT 61, -1
UNION ALL
SELECT 62, 1
UNION ALL
SELECT 63, -1
UNION ALL
SELECT 64, -1
UNION ALL
SELECT 65, -1
UNION ALL
SELECT 66, 1
UNION ALL
SELECT 67, -1
UNION ALL
SELECT 68, 1
UNION ALL
SELECT 69, 1
UNION ALL
SELECT 70, -1
UNION ALL
SELECT 71, 1
UNION ALL
SELECT 72, -1
UNION ALL
SELECT 73, -1
UNION ALL
SELECT 74, -1
UNION ALL
SELECT 75, -1
UNION ALL
SELECT 76, 0
UNION ALL
SELECT 77, 1
UNION ALL
SELECT 78, 0
UNION ALL
SELECT 79, 1
UNION ALL
SELECT 80, -1
UNION ALL
SELECT 81, -1
UNION ALL
SELECT 82, 1
UNION ALL
SELECT 83, -1
UNION ALL
SELECT 84, 0
UNION ALL
SELECT 85, -1
UNION ALL
SELECT 86, 1
UNION ALL
SELECT 87, -1
UNION ALL
SELECT 88, -1
UNION ALL
SELECT 89, -1
UNION ALL
SELECT 90, -1
UNION ALL
SELECT 91, -1
UNION ALL
SELECT 92, 0
UNION ALL
SELECT 93, -1
UNION ALL
SELECT 94, -1
UNION ALL
SELECT 95, -1
UNION ALL
SELECT 96, -1
UNION ALL
SELECT 97, -1
UNION ALL
SELECT 98, -1
UNION ALL
SELECT 99, 1
UNION ALL
SELECT 100, -1
UNION ALL
SELECT 101, 1
UNION ALL
SELECT 102, 1
UNION ALL
SELECT 103, -1
UNION ALL
SELECT 104, 1
UNION ALL
SELECT 105, -1
UNION ALL
SELECT 106, 1
UNION ALL
SELECT 107, -1
UNION ALL
SELECT 108, 1
UNION ALL
SELECT 109, 1
UNION ALL
SELECT 110, 0
UNION ALL
SELECT 111, -1
UNION ALL
SELECT 112, -1
UNION ALL
SELECT 113, 1
UNION ALL
SELECT 114, 0
UNION ALL
SELECT 115, -1
UNION ALL
SELECT 116, -1
UNION ALL
SELECT 117, 1
UNION ALL
SELECT 118, 0
UNION ALL
SELECT 119, 0
UNION ALL
SELECT 120, -1
UNION ALL
SELECT 121, 0
UNION ALL
SELECT 122, 0
UNION ALL
SELECT 123, 0
UNION ALL
SELECT 124, -1
UNION ALL
SELECT 125, 1
UNION ALL
SELECT 126, -1
UNION ALL
SELECT 127, 1
UNION ALL
SELECT 128, -1
UNION ALL
SELECT 129, -1
UNION ALL
SELECT 130, -1
UNION ALL
SELECT 131, -1
UNION ALL
SELECT 132, -1
UNION ALL
SELECT 133, -1
UNION ALL
SELECT 134, 1
UNION ALL
SELECT 135, -1
UNION ALL
SELECT 136, -1
UNION ALL
SELECT 137, -1
UNION ALL
SELECT 138, -1
UNION ALL
SELECT 139, -1
UNION ALL
SELECT 140, -1
UNION ALL
SELECT 141, -1
UNION ALL
SELECT 142, -1
UNION ALL
SELECT 143, 0
UNION ALL
SELECT 144, -1
UNION ALL
SELECT 145, -1
UNION ALL
SELECT 146, -1
UNION ALL
SELECT 147, 1
UNION ALL
SELECT 148, -1
UNION ALL
SELECT 149, 1
UNION ALL
SELECT 150, -1
UNION ALL
SELECT 151, 1
UNION ALL
SELECT 152, -1
UNION ALL
SELECT 153, 0
UNION ALL
SELECT 154, -1
UNION ALL
SELECT 155, -1
UNION ALL
SELECT 156, -1
UNION ALL
SELECT 157, -1
) AS T(ID,V) ON T.ID = AmazonCustomers.ID