0

I need help with script writing for SQL Server 2008.

I have 2 tables, Character and MEMB_INFO, and I want to run this code automatically, as a SQL Server Agent job:

SELECT MasterResetCount
FROM character
WHERE MasterResetCount = 3 OR = 5 OR 7

And in the same code add something like "IF"

That will do the test and only if MasterResetCount = 3 or = 5 or 7 And if 3,5,7 exist in MasterResetCount

Update:

update MEMB_INFO 
set AccountLevel = 1

I'd love to get help

I really don't understand writing queries.

Thank you!

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • Hello Aviad Levi, welcome to Stack Overflow. Your explanation is rather unclear. Please provide sample data from both tables and desired results (all as tabular text) to help us help you. – GMB May 03 '20 at 18:57
  • Just as a note: SQL Server 2008 and 2008 R2 are **out of extended support** by now - https://www.red-gate.com/simple-talk/sql/database-administration/the-end-of-sql-server-2008-and-2008-r2-extended-support/ - time to upgrade! – marc_s May 03 '20 at 19:07

1 Answers1

0

You can use a where clause on the update to execute it only when exists any record at the character table with MasterResetCount values of 3, 5 or 7.

update MEMB_INFO set AccountLevel = 1
where exists (select *
              from character
              where character.UserId = MEMB_INFO.UserId and
                    MasterResetCount in (3, 5, 7))
Marc Guillot
  • 6,090
  • 1
  • 15
  • 42
  • Thanks for the comment exists Doesn't really help here Because it affects all AccountLevel and changes it to 1 (in this case it affects all the users) I want AccountLevel to be updated to 1 only if The condition of the SELECT is executed    MasterResetCount 3, 5, 7 in the character table And updated the AccountLevel to 1 Only to the same user His MasterResetCount Equals TO 3 OR 5 OR 7 – Aviad Levi May 03 '20 at 21:13
  • @AviadLevi Please notice that you didn't say anything about users, when you need help you have to provide all the information to be helped. I have updated the answer so now you can see how to filter the status of MasterResetCount only to the user at MEMB_INFO. Regards. – Marc Guillot May 04 '20 at 06:31