0

想象有 2 张桌子:

T_Customer (p_customer_id, name, prename, country, age)

T_SomeInfo (f_customer_id, somebit, otherbit)

现在我想更新 1 个 randomsomebitOUTPUTupdated T_Customer,它属于f_customer_id受影响的行。

Atm 我有以下声明:

UPDATE randombit SET randombit.somebit= 1
OUTPUT inserted.f_customer_id
FROM 
(
SELECT TOP 1 * FROM T_SomeInfo  
WHERE somebit= 0 AND otherbit = 0
ORDER BY NEWID()
) AS randombit

所以f_customer_id我更新了我的行。但是我无法构建一个有效的语句来从另一个表中输出一个值。这是我尝试但没有成功的声明:

UPDATE randombit SET randombit.somebit= 1
OUTPUT customer.*
FROM T_Customer AS customer
WHERE customer.f_customer_id = inserted.f_customer_id
FROM 
(
SELECT TOP 1 * FROM T_SomeInfo  
WHERE somebit= 0 AND otherbit = 0
ORDER BY NEWID()
) AS randombit

是否有任何解决方案可以更新和输出(使用INNER JOINSELECT)到一个语句中?

编辑例如:有 2 个客户:

T_Customer (1, "Smith", "John", "country", 10)
T_Customer (2, "John", "William", "country2", 20)

实际上是更新

UPDATE randombit SET randombit.somebit= 1
OUTPUT inserted.f_customer_id
FROM 
(
SELECT TOP 1 * FROM T_SomeInfo  
WHERE somebit= 0 AND otherbit = 0
ORDER BY NEWID()
) AS randombit

将输出(如果他是随机获胜者):

1

但我想看看

1、《史密斯》、《约翰》、《乡村》、10

4

0 回答 0