Wrox Programmer Forums
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 9th, 2004, 03:57 PM
Registered User
 
Join Date: Jun 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default UPDATE with joined tables

I am new to MSSQL and have some UPDATE queries from Access that use INNER JOIN that I'd like to use in the MSSQL version of the database. Copying the Access version into Analyzer and checking syntax just doesn't like the INNER JOIN line. Anyone got any ideas. Both tables have IDENTITY fields.

Thanks!

Dan

 
Old June 9th, 2004, 04:20 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hello,

In SQL, an inner join should work, here's an example:

select a.ID, a.Name from TableA a
inner join TableB b
on a.ID = b.AID

a and b are table aliases, and could be written out with the Table Name instead. This example uses the ID in table A (primary key) to relate to the foreign key (AID) in table b.

Brian
 
Old June 9th, 2004, 08:04 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Dan,

Can you post your query so that let us suggest you if any corretions needed?

Cheers!

_________________________
-Vijay G
Strive for Perfection
 
Old June 9th, 2004, 11:26 PM
Authorized User
 
Join Date: Jun 2003
Posts: 77
Thanks: 0
Thanked 0 Times in 0 Posts
Default

an update with inner join looks like this:

update x
set field1 = value1,
    field2 = value2,
    ...
from table1 x
    inner join table2 y on x.somefield = y.somefield
 
Old July 6th, 2004, 08:30 AM
Registered User
 
Join Date: Jul 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I usually find that solving UPDATEs that apparently require INNER JOIN need to use a subselect something like this...

UPDATE table1
set field1 = value1,
    field2 = value2,
    ...
WHERE Identity col IN(
SELECT Identity col....
from table1 x
    inner join table2 y on x.somefield = y.somefield
)







Similar Threads
Thread Thread Starter Forum Replies Last Post
Listing results from joined tables henry-horse Classic ASP Basics 5 March 9th, 2007 07:08 AM
How to update more than 2 tables walgr2k ASP.NET 2.0 Basics 1 May 19th, 2006 02:01 PM
fields from tables to update damnnono_86 Access 3 November 5th, 2003 04:07 AM
update tables jjebb Access 7 October 27th, 2003 12:26 PM
inserting into joined tables cjennings SQL Server 2000 3 July 23rd, 2003 06:10 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.