SpaceCoastLife
asked on
Trying to run an update query in SQL Server using 2 tables from 2 attached databases
--Sites
UPDATE db1.dbo.Post
SET db1.dbo.Post.GId = db1.dbo.routeGroup.SiteCod e
FROM db1.dbo.Post
INNER JOIN db2
ON (db1.dbo.Post.CustomerId = db2.dbo.Meals_In.mls_prt_f k)
The result is all the references to db2 are underlined in red (invalid object name) even though I have verified both databases are attached and the names are correct.
Any suggestions anyone?
UPDATE db1.dbo.Post
SET db1.dbo.Post.GId = db1.dbo.routeGroup.SiteCod
FROM db1.dbo.Post
INNER JOIN db2
ON (db1.dbo.Post.CustomerId = db2.dbo.Meals_In.mls_prt_f
The result is all the references to db2 are underlined in red (invalid object name) even though I have verified both databases are attached and the names are correct.
Any suggestions anyone?
ASKER
Would you add your suggestions into my statement to make sure I understand?
As you can probably tell, I have very limited experience working with Sql Server - and I have no idea how to go about using aliases.
Would you also consider showing what the corrected version of my statement would look like with aliases? I'd very much appreciate it.
As you can probably tell, I have very limited experience working with Sql Server - and I have no idea how to go about using aliases.
Would you also consider showing what the corrected version of my statement would look like with aliases? I'd very much appreciate it.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for the help.
The INNER JOIN is expecting a table or view name, even if it's a fully qualified database_name.schema_name.
>SET db1.dbo.Post.GId = db1.dbo.routeGroup.SiteCod
The table routeGroup is not defined in your FROM block.
Using table aliases would make this much easier to read