我在下面的SQL中收到此错误:
子查询返回的值超过1。当子查询遵循=,!=,<,< =,>,> =或子查询用作表达式时,不允许这样做。
有人知道如何解决它吗?
use character
DECLARE @guild_codex varchar(25)
DECLARE @character_name0 varchar(40)
DECLARE @user_no0 varchar (25), @id varchar (25)
DECLARE @user_no varchar (25), @group_id varchar (25), @amount varchar (25)
DECLARE @free_amount varchar(25), @2mx_Leader varchar(3), @2mx_member varchar (3)
SET @2mx_Leader = 700 SET @2mx_member = 500 SET @id = (SELECT id from
[PC-ID].[Cash].[dbo].[user_cash] where free_amount LIKE 0) SET
@user_no = (SELECT user_no from [PC-ID].[Cash].[dbo].[user_cash]
where free_amount LIKE 0) SET @group_id = (SELECT group_id from
[PC-ID].[Cash].[dbo].[user_cash] where free_amount LIKE 0) SET
@amount = (SELECT amount from [PC-ID].[Cash].[dbo].[user_cash]
where free_amount LIKE 0) SET @free_amount = (SELECT free_amount from
[PC-ID].[Cash].[dbo].[user_cash] where free_amount LIKE 0) SET
@guild_codex = (SELECT guild_code from siege_info where siege_tag LIKE'Y')
SET @character_name0 = (SELECT character_name from guild_char_info
where guild_code LIKE @guild_codex and peerage_code LIKE 0) SET
@user_no0 = (SELECT user_no from user_character where character_name
LIKE @character_name0)
use cash
UPDATE user_cash SET
amount=amount+@2mx_Leader WHERE user_no = @user_no0
答案 0 :(得分:0)
SQL的多个问题
要为多个变量赋值,从同一个表中选择,使用相同的where子句,您可以多次访问数据库,同时可以在一次调用中完成,如下所示:
SELECT
@id = id,
@user_no = user_no,
@group_id = group_id,
@amount = amount,
@free_amount = free_amount
FROM [PC-ID].[Cash].[dbo].[user_cash]
WHERE free_amount LIKE 0
您正在使用LIKE,它可能会返回多行数据,如错误消息中所述。如果可以的话,尝试使用=。或者,尝试执行负责填充变量的Select语句,以查看是否返回了多行数据。
拉吉