sql query refrence data on a alternate table to change specific values to false

i have 2 tables, the primary table [dbo.subscriber data] has several columns. the columns i need to reference on the primary table are 'AccountID' and 'AcctLineCode'
the other table is [dbo.subscriber Status], it also has the 'AccountID' column as well as the column 'IsRecurring'
i need to change all instances of 'IsRecurring' on [dbo.subscriber Status] to False if it has an 'AccountID' that matches the 'AccountID' from [dbo.subscriber data] that has an 'AcctLineCode' of 'HR' or 'HRS'

I assume i need to use inner join, i have no idea the syntax
LVL 1
csePixelatedAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

awking00Information Technology SpecialistCommented:
update [dbo.subscriber Status] s
set IsRecurring = False
where exists
(select 1 from [dbo_subscriber Data] d
 where d.AccountID = s.AccountID
 and d.AcctLineCode like 'HR_');
1
csePixelatedAuthor Commented:
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near 's'.
0
csePixelatedAuthor Commented:
removed the s from line one and the d from line 4, checked sql passed, ran it and got...
Msg 208, Level 16, State 1, Line 1
Invalid object name 'dbo.subscriber Status'.
0
IT Pros Agree: AI and Machine Learning Key

We’d all like to think our company’s data is well protected, but when you ask IT professionals they admit the data probably is not as safe as it could be.

csePixelatedAuthor Commented:
update [dbo.subscriber Status]
set IsRecurring = False
where exists
(select 1 from [dbo_subscriber Data] d
 where d.AccountID = s.AccountID
 and d.AcctLineCode like 'HR_');

ran the above
still got
Msg 208, Level 16, State 1, Line 1
Invalid object name 'dbo.subscriber Status'.
0
awking00Information Technology SpecialistCommented:
What are the actual case sensitive names of your tables
0
csePixelatedAuthor Commented:
[dbo.Subscriber Data] & [dbo.Subscriber Status] are the actual case sensitive names of the tables.
i have now tryed with these corected...

update [dbo.Subscriber Status]s
set IsRecurring = False
where exists
(select 1 from [dbo_Subscriber Data] d
 where d.AccountID = s.AccountID
 and d.AcctLineCode like 'HR_');

still getting...
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near 's'.
0
csePixelatedAuthor Commented:
noticed a lack of space...
update [dbo.Subscriber Status] s
set IsRecurring = False
where exists
(select 1 from [dbo_Subscriber Data] d
 where d.AccountID = s.AccountID
 and d.AcctLineCode like 'HR_');
still
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near 's'.
0
awking00Information Technology SpecialistCommented:
Might need AS keyword?
update [dbo.Subscriber Status] AS  s
 set IsRecurring = False
 where exists
 (select 1 from [dbo_Subscriber Data] AS d
  where d.AccountID = s.AccountID
  and d.AcctLineCode like 'HR_');
0
csePixelatedAuthor Commented:
update [dbo.Subscriber Status] AS "s"
 set IsRecurring = False
 where exists
 (select 1 from [dbo_Subscriber Data] AS "d"
  where d.AccountID = s.AccountID
  and d.AcctLineCode like 'HR_');

Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'AS'.

update [dbo.Subscriber Status] AS s
 set IsRecurring = False
 where exists
 (select 1 from [dbo_Subscriber Data] AS d
  where d.AccountID = s.AccountID
  and d.AcctLineCode like 'HR_');

Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'AS'.
0
csePixelatedAuthor Commented:
i was curious as to weather i needed the In clause, did some playing around

update [Subscriber Status]
 set IsRecurring = 'False'
 where exists
 (select 1 from [Subscriber Data] AS d
  where d.AccountID = AccountID
  and d.AcctLineCode like 'HR_');

this ran however too many rows were affected
0
csePixelatedAuthor Commented:
yea it changed every IsRecurring to 'false'
0
Scott PletcherSenior DBACommented:
UPDATE ss
SET IsRecurring = 0 /*'F'*/
FROM [dbo.subscriber Status] ss
INNER JOIN (
    SELECT AccountID
    FROM [dbo.subscriber data]
    WHERE AcctLineCode IN ('HR', 'HRS')
    GROUP BY AccountID
) AS sd ON sd.AccountID = ss.AccountID
1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
csePixelatedAuthor Commented:
aparently it did not like the "dbo."

UPDATE ss
SET IsRecurring = 0 /*'F'*/
FROM [Subscriber Status] ss
INNER JOIN (
    SELECT AccountID
    FROM [Subscriber Data]
    WHERE AcctLineCode IN ('HR', 'HRS')
    GROUP BY AccountID
) AS sd ON sd.AccountID = ss.AccountID

the above worked perfectly..,. TY Scott P and Awking00..!!
0
Scott PletcherSenior DBACommented:
D'OH, sorry, the "dbo." should have been separate, before the brackets.

UPDATE ss
SET IsRecurring = 0
FROM dbo.[subscriber Status] ss
INNER JOIN (
    SELECT AccountID
    FROM dbo.[subscriber data]
    WHERE AcctLineCode IN ('HR', 'HRS')
    GROUP BY AccountID
) AS sd ON sd.AccountID = ss.AccountID

Btw, ALWAYS use an alias when UPDATEing a table using a JOIN.  Otherwise, it's too easy to UPDATE all rows and/or the wrong rows in the table being updated.  Like above:

UPDATE ss --<< alias name (not [subscriber Status] directly)
SET IsRecurring = 0
FROM dbo.[subscriber Status] ss --<< assign alias name for use in UPDATE
1
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
SQL

From novice to tech pro — start learning today.