Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Update SQL

Author  Topic 

benking9987
Posting Yak Master

124 Posts

Posted - 2010-03-19 : 18:48:49
I'm not so good with SQL syntax. I generally use my MS Access front end to create the queries I need. HOWEVER, I'm trying to program a T-SQL job that I can call from the SQL Agent. This is what the MS SQL query designer is giving me. Given that MS Access is apparently not ANSI SQL compliant, I think there are some syntax issues.

I have two tables (Master_Parent, Master_Child) The field Master_Parent is the PK of the Master_Parent table and it is an FK in the Master_Child table. I want to join the two tables on that field and then update Master_Child.OS_Active (a bit datatype) based on criteria found in the Master_Parent and Master_Child tables:



UPDATE Master_Parent INNER JOIN Master_Child ON Master_Parent.Master_Parent = Master_Child.Master_Parent SET Master_Child.OS_Active = 0
WHERE (((Master_Parent.PurchaseAuthorization)="Closed") AND ((Master_Child.OS_Child) Is Not Null));

I'm getting this error:

Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'INNER'.
Msg 102, Level 15, State 1, Line 2
Incorrect syntax near 'Master_Parent'.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-03-19 : 18:52:47
Try this:

UPDATE Master_Parent
SET OS_Active = 0
FROM Master_Parent
INNER JOIN Master_Child
ON Master_Parent.Master_Parent = Master_Child.Master_Parent
WHERE Master_Parent.PurchaseAuthorization='Closed' AND Master_Child.OS_Child Is Not Null;

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -