returns more than one SQL result under query for trigger?

0

I have this trigger script created by me which executes a perfect UPDATE when it is a single user but when it is more than one or several User Fails the query by the trigger (BEFORE NOTHING SEARCH ON INTERNET that has to do with TOP 1 or IN the problem is the next)

The trigger is as follows:

USE [PS_GameData]
GO
/****** Object:  Trigger [dbo].[Utilidad_4]    Script Date: 09/16/2016 08:29:14 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


-- =============================================
-- Author:      DEVjuan,,Juan>
-- Create date: 06-04-2016>
-- Description: AntiLinkeos de Capas y Encanto de Capas
-- =============================================
ALTER TRIGGER [dbo].[Utilidad_4]
   ON  [dbo].[Chars]
   AFTER UPDATE

AS




DECLARE 
@level_60 int = 835,
@level_30 int = 589,
@level_15 int = 134,
@CharName Varchar (250) =(SELECT TOP 1 CharName FROM INSERTED),
@CharID int = (SELECT TOP 1 CharID FROM INSERTED),--Chars WHERE CharName = @CharName),
@STR60 int = 836,
@DEX60 int = 836,
@REC60 int = 836,
@WIS60 int = 836,
@INT60 int = 836,
@LUC60 int = 836,
@STR30 int = 590,
@DEX30 int = 590,
@REC30 int = 590,
@WIS30 int = 590,
@INT30 int = 590,
@LUC30 int = 590,
@STR15 int = 135,
@DEX15 int = 135,
@REC15 int = 135,
@WIS15 int = 135,
@INT15 int = 135,
@LUC15 int = 135,

@STR60_insert int = (SELECT STR FROM INSERTED)


--------------------------------------------------------------------------------------------------------------------------------------------------
--Anti edicion de PJ pvp 1-60

IF (SELECT @STR60_insert)>0
    BEGIN
            CREATE TABLE #TempSTR60(STR1 int,STR2 int);
            INSERT INTO #TempSTR60 Values(@STR60_insert,@STR60);
            IF (SELECT [STR1] FROM #TempSTR60 WHERE [STR1] = @STR60_insert) > (SELECT [STR2] FROM #TempSTR60 WHERE [STR2] = @STR60)
                    BEGIN
                        UPDATE PS_GameData.dbo.Chars SET STR = @level_60, DEX = 0,REC = 0,WIS = 0,INT = 0,LUC = 0
                        WHERE STR > @STR60  and level BETWEEN 31 and 60  and CharID in (SELECT CharID FROM Chars WHERE CharName [email protected])
                        OR STR > @STR60  and level BETWEEN 31 and 60  and CharID in (@CharID) 
                        PRINT 'EDITADO 60 STR del CharName '+CONVERT(varchar(3), @CharName)
                        DROP Table #TempSTR60
                    END
    END 
ELSE PRINT 'STR NO'
PRINT 'FIN'

Queries that fail These are:

UPDATE PS_GameData.dbo.Chars SET 
STR = STR

UPDATE PS_GameData.dbo.Chars SET 
STR = 1000 

The query that happens good is this:

 UPDATE PS_GameData.dbo.Chars SET 
    STR = 1000 
    WHERE CharID = '57803'

PROBLEM: the problem Causes this:

@STR60_insert int = (SELECT STR FROM INSERTED)

I know another way to take the inserted data or to update it. These two but none has helped me.

 SET @STR60_insert int = (SELECT STR FROM INSERTED)
 SET @STR60_insert int = (SELECT STR FROM DELETED)

I ask how can I take the inserted data and at the same time be able to execute the queries that give problems so that the trigger fits me both with the one that gives the query good and the one that is wrong?

    
asked by Juan Carlos Villamizar Alvarez 16.09.2016 в 20:14
source

1 answer

1

After so much work I saw the answer xD

SELECT Top 1 in

@STR60_insert int = (SELECT STR FROM INSERTED)
    
answered by 24.09.2016 / 02:46
source