John Beynon

Confessions of a code Junkie and anything else i fancy!

SQL 2005 Update From

This is more for my own benefit, but I thought I’d add it here so all can see (and I can find later).

A client sent over a spreadsheet containing 2 columns, the PK and a column of string data. They wanted this data to be used to update existing data in their application.

My first thought was to reach for CF and do it there but SQL 2005 makes this task real simple (I found after a little bit of investigation).

First up, I imported the spreadsheet into a temp table (tempdata) and then using 4 lines of SQL updated the original table using the values from the temp table using the SQL 2005 Update FROM clause;

update objProduct
set displayname = tempdata.displayname
from objProduct,tempdata
where objProduct.productSKU = tempdata.productSKU

simple huh?

No related posts.

Tagged as:

2 Comments

  1. All I have to say is WOW.

  2. A simple explanation… Thanks!

Leave a Response