Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2005 > SQL Server 2005
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
SQL Server 2005 General discussion of SQL Server *2005* version only.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2005 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 January 7th, 2008, 02:28 PM
Authorized User
 
Join Date: Aug 2003
Location: Pittsburgh, PA, USA.
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default update table from another db table

I have a problem trying to write a query in SQL server 2005.

I want to update records in a table in one database from another table in a different database.
The code is below:

update orig.dbo.[credit]
    set orig.dbo.[credit].[limit] = tempdb.dbo.[customer_limits].[cr_limit_amt]
         from temp.dbo.[customer_limits]
    where temp.dbo.[customer_limits].[cr_acct_id] = orig.dbo.[credit].[legacy_id]

The code parses fine, but when I click the 'Execute' button, I get the error message below:

Msg 207, Level 16, State 1, Line 3
Invalid column name 'limit'.

Please help.
Thanks,
-Tim
Reply With Quote
  #2 (permalink)  
Old January 7th, 2008, 04:16 PM
Authorized User
 
Join Date: Aug 2003
Location: Pittsburgh, PA, USA.
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

ok..i overlooked my field names... I had a misspelling in the code vs the table. The field in the table is climit instead of limit. So after updating the code...it worked fine.
Reply With Quote
  #3 (permalink)  
Old January 7th, 2008, 04:30 PM
SQLScott's Avatar
Wrox Author
 
Join Date: Dec 2004
Location: Wellington, FL , USA.
Posts: 338
Thanks: 0
Thanked 2 Times in 2 Posts
Default

I just tried this on some of our databases and it worked, so I can only think of two reasons why it would not work for you.

1) you mispelled your column name
2) Try aliasing one side of your query, meaning:


update orig.dbo.[credit]
set orig.dbo.[credit].[limit] = t.[cr_limit_amt]
from temp.dbo.[customer_limits] t
where t.[cr_acct_id] = orig.dbo.[credit].[legacy_id]

or, you could alias both sides as well.

Let us know what happens.


========================
Scott Klein
Author of:
Professional SQL Server 2005 XML
Professional WCF Programming: .NET Development with the Windows Communication Foundation
Professional LINQ
========================
Reply With Quote
  #4 (permalink)  
Old January 19th, 2008, 06:47 AM
Authorized User
 
Join Date: Jun 2007
Location: pune, Mah, India.
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

update orig.dbo.[credit]
set orig.dbo.[credit].[limit] = t.[cr_limit_amt]
from temp.dbo.[customer_limits] t
where t.[cr_acct_id] = orig.dbo.[credit].[legacy_id]
 solve u problem

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
Update one table to another table using DTS in SQL Printmaker SQL Language 0 July 24th, 2007 07:17 AM
Table to Table Update amerifax Access 1 July 10th, 2007 02:41 AM
How to Update one table with other table data? ramk_1978 SQL Language 2 May 26th, 2006 12:51 AM
update table with an ID Num from different table scoobie PHP How-To 12 January 25th, 2005 12:28 PM
Update parent table with the sum of child table gbrown SQL Language 2 November 9th, 2004 07:53 AM



All times are GMT -4. The time now is 02:21 PM.


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