正确声明运算符时出现问题插入查询SQL Server

iaqfqrcu  于 2023-02-07  发布在  SQL Server
关注(0)|答案(1)|浏览(100)

查询执行,但它只影响1行,这是第一个找到的。我设法让它的工作,因为预期这里是工作查询:

select * 
from Game.dbo.TCharacterAbility;

select t.user_id, i.* 
from TCharacterAbility as i 
join TCharacter as t on i.char_id = t.id
where (i.strength > '746' or 
       i.dexterity > '746' or 
       i.quickness > '746' or 
       i.mentality > '746' or 
       i.health > '746' or 
       i.intelligence > '746')

下面是我纠结的一个问题:

DEClARE @user_id int;
DEClARE @char_id int;

SELECT @char_id = id 
FROM TCharacter as x 
INNER JOIN tcharacterability y ON x.id = y.char_id 
WHERE (y.strength > '746' OR y.dexterity > '746' OR 
       y.quickness > '746' OR  y.mentality > '746' OR 
       y.health > '746' OR y.intelligence > '746')

SELECT @user_id = user_id 
FROM TCharacter as x 
INNER JOIN tcharacterability y ON x.id = y.char_id 
WHERE (y.strength > '746' OR y.dexterity > '746' OR 
       y.quickness > '746' OR y.mentality > '746' OR 
       y.health > '746' OR y.intelligence > '746')

INSERT INTO [User].[dbo].[TDisconnect] (user_id, server_id, char_id) VALUES (@user_id, 1, @char_id)

我已经尽我所能地声明了操作符,但是失败得很惨。
有关这些表的详细信息
t.characterability-色谱柱:

char_id | strength | dexterity | mentality | quickness | health | intelligence |

t.character

id (equal to char_id from characterability) | user_id | name | etc |

除了id = char_id之外,没有其他共享信息。
我的目标是这个查询找到所有的结果,而不仅仅是第一个结果,并插入适当数量的匹配项。

0dxa2lsx

0dxa2lsx1#

变量可以是标量值,并且不能保存多个值,因此需要另一种方法来实现

INSERT INTO [User].[dbo].[TDisconnect] (user_id,server_id,char_id) 
SELECT user_id,1,id 
from TCharacter as x INNER JOIN tcharacterability y on x.id =y.char_id 
where (y.strength >'746' or y.dexterity>'746' or y.quickness>'746' or y.mentality>'746' or y.health>'746' or y.intelligence>'746')

相关问题