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
 General SQL Server Forums
 New to SQL Server Programming
 simple: cross check reference table and amend

Author  Topic 

workindan
Starting Member

21 Posts

Posted - 2010-11-08 : 15:18:03
Hello, I'm new to sql programming (I've done some of the basics) and had a question:

I have two tables: tbl1, tbl2

tbl1 has two important fields: 1) item_type 2)item_brand (and other fields)
tbl1 has hundreds of records with item_type already completed, but item_brand is null

tbl2 is the reference table, it has 1) item_type and 2) item_brand
It has all the unique types and there brand reference


What would be the code to amend tbl1 by referencing the right brand from tbl2? I'm attempting to get it to work on my own before I execute on real world data.

Thanks!

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-11-08 : 15:28:30
Show us a data example to make this more clear.

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

Subscribe to my blog
Go to Top of Page

workindan
Starting Member

21 Posts

Posted - 2010-11-09 : 12:59:37
[code]
(table: people)
name id item_type item_brand
marge 0 circle
bob 1 block
jill 2 square
masdf 3 circle
adf 4 triangle

(table: itemref)
item_type item_brand
block mattell
circle helper
square mattyz
triangle nathan
adfadsf 5 block
[/code]

As I understand it, an UPDATE using INNER JOIN would work. I seem to be confused on the syntax, though...
Go to Top of Page

workindan
Starting Member

21 Posts

Posted - 2010-11-09 : 13:14:35
Here's the one I'm using:

UPDATE people set item_brand=itemref.item_brand FROM people INNER JOIN itemref on people.item_type=itemref.item_type WHERE people.item_brand is null;

But when I try to execute it (these are test tables in Access 2003), I get this: "Syntax error (missing operator) in query expression 'itemref.item_brand FROM people INNER JOIN itemref on people.item_type=itemref.item_type'
Go to Top of Page
   

- Advertisement -