-1

大家好,我在数据库 sql 上创建了一个新系统,然后我得到这是错误的

Msg 512, Level 16, State 1, Line 1
Subquery returned more than 1 value. This is not permitted when the subquery follows 
=, !=, <, <= , >, >= or when the subquery is used as an expression.

这是一个查询

Declare @Weapon INT = (Select ItemID From SRO_VT_SHARD.dbo._Inventory WITH (Nolock)      Where CharID = @CharID 
AND Slot in (Select Slot From SRO_VT_SHARD.dbo._Inventory Where CharID = @CharID And Slot   Between '6' And '7'))

Declare @WeaponType3 Tinyint =
 (Select Typeid3 from SRO_VT_SHARD.dbo._RefObjCommon where ID in 
 (Select RefItemID from SRO_VT_SHARD.dbo._Items where ID64=@Weapon))

Declare @WeaponType4 Tinyint =
(Select Typeid4 from SRO_VT_SHARD.dbo._RefObjCommon where ID = 
(Select RefItemID from SRO_VT_SHARD.dbo._Items where ID64=@Weapon))

declare @RefWeapon int = (Select top 1 ID from SRO_VT_SHARD.dbo._RefObjCommon WITH (Nolock) where 
                    Service = 1 AND
                    TypeID1=3 AND --- Weapon
                    TypeID2=1 AND
                    TypeID3=@WeaponType3 AND
                    TypeID4=@WeaponType4
                    Group by SRO_VT_SHARD.dbo._RefObjCommon.ID,SRO_VT_SHARD.dbo._RefObjCommon.reqlevel1
                    having  (MAX(ReqLevel1)<=(Select CurLevel from SRO_VT_SHARD.dbo._Char where charid = @CharID))
                    Order By ReqLevel1 Desc 
               )
if (@RefWeapon is not null) And (@Weapon is not null) And (@WeaponType3 is not null)     And (@WeaponType4 is not null)
begin
               Update SRO_VT_SHARD.dbo._Items set RefItemID= @refweapon where ID64=     @Weapon
end

我需要解决这个问题是查询

4

2 回答 2

0

好的,如果我没记错的话,你会在这里得到你的错误代码

declare @RefWeapon int = (Select top 1 ID from SRO_VT_SHARD.dbo._RefObjCommon WITH (Nolock) where 
                    Service = 1 AND
                    TypeID1=3 AND --- Weapon
                    TypeID2=1 AND
                    TypeID3=@WeaponType3 AND
                    TypeID4=@WeaponType4
                    Group by SRO_VT_SHARD.dbo._RefObjCommon.ID,SRO_VT_SHARD.dbo._RefObjCommon.reqlevel1
                    having  (MAX(ReqLevel1)<=(Select CurLevel from SRO_VT_SHARD.dbo._Char where charid = @CharID))
                    Order By ReqLevel1 Desc 
               )

特别是在这部分

having  (MAX(ReqLevel1)<=(Select CurLevel from SRO_VT_SHARD.dbo._Char where charid = @CharID))

为什么?好的,MAX(ReqLevel1)是 1 个值,但(Select CurLevel from SRO_VT_SHARD.dbo._Char where charid = @CharID)会返回很多值。所以你无法比较它们

你可能应该使用

(Select TOP 1 CurLevel from SRO_VT_SHARD.dbo._Char where charid = @CharID)

对不起,我的英语不好。希望这有帮助!

于 2013-08-14T23:09:38.310 回答
0

这里的问题是子查询返回多行: SELECT TOP 1,或者您可以将 = 切换为 IN 并返回多行

例子 :

SELECT t.ParentId,t1.parentname as parentname, t.childid as childid, 
   (select TOP 1 table1.childid from table1 where table1 .childname=table2.childid) as childname
FROM table1 t
left JOIN table2 t1 ON t.ParentId = t1.childid

--->在这里使用你的代码

于 2014-10-28T05:21:23.463 回答