Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2005 > SQL Server 2005
|
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 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 January 7th, 2008, 02:28 PM
Authorized User
 
Join Date: Aug 2003
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
 
Old January 7th, 2008, 04:16 PM
Authorized User
 
Join Date: Aug 2003
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.
 
Old January 7th, 2008, 04:30 PM
SQLScott's Avatar
Wrox Author
 
Join Date: Dec 2004
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
========================
 
Old January 19th, 2008, 06:47 AM
Authorized User
 
Join Date: Jun 2007
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






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





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