Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 9th, 2004, 03:57 PM
Registered User
 
Join Date: Jun 2004
Location: , , .
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

Reply With Quote
  #2 (permalink)  
Old June 9th, 2004, 04:20 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Harrisburg, PA, USA.
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
Reply With Quote
  #3 (permalink)  
Old June 9th, 2004, 08:04 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Bangalore, KA, India.
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
Reply With Quote
  #4 (permalink)  
Old June 9th, 2004, 11:26 PM
Authorized User
 
Join Date: Jun 2003
Location: , , Romania.
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
Reply With Quote
  #5 (permalink)  
Old July 6th, 2004, 08:30 AM
Registered User
 
Join Date: Jul 2004
Location: Stoke, , United Kingdom.
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
)


Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 06:54 AM.


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