SQL: cross-table updates

Because I always forget how to do it, and always have to look up the syntax... Here's how to update table A with values from table B.

UPDATE A
SET name = B.name
FROM B
WHERE A.id = B.id;

SQL can't format SQL

I'm full of complaints lately. I spent a great deal of time writing a beautifully formatted, very human readable SQL query. Then I saved it as a view and SQL Server was kind enough to reformat it as a big block of text, horribly aligned, impossible to read. Die in a fire, Microsoft.

BlogCFC was created by Raymond Camden. This blog is running version 5.9.002. Contact Blog Owner