如何在sql server中使用多个唯一值更新多个列?
如果我继续下面的方法,需要手动输入1000行...这很难......
以下给出的示例数据:(最多需要更新1000行)
UPDATE buid
SET Country_Code = CASE Business_Unit_ID
WHEN 5959 THEN CA
WHEN 930102 THEN US
WHEN 3737 THEN CN
.
.
.
.
.
.
END,
Country_NAME = CASE Business_Unit_ID
WHEN 5959 THEN Canada
WHEN 930102 THEN USA
WHEN 3737 THEN China
.
.
.
.
.
.
END
WHERE Business_Unit_ID IN (5959,
930102,
3737
.
.
.
.
.
答案 0 :(得分:1)
你需要一张可以加入的桌子,即
import threading
import time
class myThread(object):
"""
The run() method will be started and it will run in the background
until the application exits.
"""
def __init__(self, interval=1):
self.interval = interval
self.thread_stack = []
thread = threading.Thread(target=self.run, args=())
thread.daemon = True
thread.start()
def run(self):
# Method that runs forever
lock = threading.Lock()
while True:
if self.thread_stack:
lock.acquire()
try:
# if a method is already running on this thread, end it.
new_function = thread_stack.pop()
finally:
lock.release()
# run new function
else:
time.sleep(self.interval)
def some_function(self):
#do something
#do something
#do something else
#do one more thing
然后你可以进行连接来更新表格:
Business_Unit(Business_Unit_ID int, Country_NAME varchar(50), Country_Code varchar(2))