0

I'm trying to figure out a way to do a update on the database but I keep failing. I can't really think of something else.

  IF @EventID = 9
   BEGIN
   declare @HwanLevel int;
   UPDATE SRO_VT_SHARD.._Char set HwanLevel = 1 WHERE CharID in (SELECT TOP(1) EXP,LEVEL,CONTRIBUTION FROM SRO_VT_SHARD.._CharTrijob WHERE JobType = 1 AND CharID = @CharID)
   UPDATE SRO_VT_SHARD.._Char set HwanLevel = 2 WHERE CharID in (SELECT TOP(1) EXP,LEVEL,CONTRIBUTION FROM SRO_VT_SHARD.._CharTrijob WHERE JobType = 2 AND CharID = @CharID)
   UPDATE SRO_VT_SHARD.._Char set HwanLevel = 3 WHERE CharID in (SELECT TOP(1) EXP,LEVEL,CONTRIBUTION FROM SRO_VT_SHARD.._CharTrijob WHERE JobType = 3 AND CharID = @CharID)
   END

OHH and when I tried to use it I kept getting; "Only one expression can be specified in the select list when the subquery is not introduced with EXISTS." I have tried joins etc and case when but didn't really work out. what I'm trying to do is:

SELECT Top(1) EXP,Contribution,Level
THEN check if Jobtype = 1 then set HwanLevel to 1
if jobtype = 2 then set hwanlevel to 2
etc until 3

2 Answers 2

1

The subquery you're returning has too many fields declared. Return only one field. So it should look:

SELECT CharID 
FROM SRO_VT_SHARD.._CharTrijob 
WHERE JobType = 1 AND CharID = @CharID
Sign up to request clarification or add additional context in comments.

5 Comments

Uhm.. I wanna get the top charids using exp,contribution,level columns from SRO_VT_SHARD.._CharTrijob for this to work. Do you know any other way to do it?
UPDATE _Char set HwanLevel = (SELECT TOP(1) JobType FROM _CharTrijob WHERE _CharTrijob.CharID = _Char.CharID)
I meant.. I gotta select TOP(1) Exp, Contribution, Level Not JobType.. that's what I have been failing in until now.
Why do you need to return "Exp, Contribution, Level" fields if you only need the _Char.JobType to be updated from _CharTrijob.JobType field? You have no use for these 3 fields? According to you, you need _Char.JobType to be updated with the same value as the Top 1 from _CharTrijob.JobType with the same charid. Am I correct?
I'm giving a title in my server, The top player in job gets a title. There are 3 titles; #1 Hunter #1 Trader #1 Thief So I gotta use Select TOP(1) EXP,Contribution,Level for it to work. To get the top players in the server. Without it the whole query is useless.. Jobtype is only used to check if the player is thief or hunter or trader
0

Your top(1) is only going to respond to an ORDER BY clause in your query. It would be better to do somehting along the lines of:

UPDATE SRO_VT_SHARD.._Char SET HwanLevel = Jobtype WHERE Jobtype = (select top(1)
Jobtype FROM SRO_VT_SHARD.._CharTrijob ORDER BY EXP,LEVEL,CONTRIBUTION)

Of course it depends on the sequence of columns in the ORDER BY, if the given sequence produces the top player then good, otherwise you can re-order the sequence within the ORDER BY ie:

...ORDER BY CONTRIBUTION,EXP,LEVEL

How about using the variable, setting the variable according to the Jobtype given by the TOP 1 SELECT and then updating the other table from the variable:

DECLARE @HWANLEVEL INT
SET @HWANLEVEL = (SELECT TOP 1 Jobtype FROM SRO_VT_SHARD.._CharTrijob 
                  ORDER BY EXP,LEVEL,CONTRIBUTION)
UPDATE SRO_VT_SHARD.._Char SET HwanLevel = @HWANLEVEL  

1 Comment

I was mainly just trying to make it clear that it would need an ORDER BY clause in it...I've added a bit more to my answer which might make it make work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.