473,379 Members | 1,337 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

Update a table by copying a column from another table

I need to update a table by copying a column from another table
(having the same

structure, but on another database), from the record having the same
primary key.

1 - What is the correct query?

2 - I tried copying them record by record, but the datatype is ntext,
(it displays <long

text> in the result pane), and trying to update it results in the
following error

message:
The text, ntext, and image data types are invalid in this subquery or
aggregate

expression.

I tried variations of the following:

UPDATE TABLE
SET column0 = (
SELECT column0
FROM anotherDB.dbo.TABLE
WHERE anotherDB.dbo.TABLE.column1 = column1
)
WHERE anotherDB.dbo.TABLE.column1 = column1
Jul 20 '05 #1
1 32332

"Caroline" <pl***@letsdothatagain.com> wrote in message
news:da**************************@posting.google.c om...
I need to update a table by copying a column from another table
(having the same

structure, but on another database), from the record having the same
primary key.

1 - What is the correct query?

2 - I tried copying them record by record, but the datatype is ntext,
(it displays <long

text> in the result pane), and trying to update it results in the
following error

message:
The text, ntext, and image data types are invalid in this subquery or
aggregate

expression.

I tried variations of the following:

UPDATE TABLE
SET column0 = (
SELECT column0
FROM anotherDB.dbo.TABLE
WHERE anotherDB.dbo.TABLE.column1 = column1
)
WHERE anotherDB.dbo.TABLE.column1 = column1


This should work, assuming you always join on the primary key column:

update MyTable
set NtextColumn = ot.NtextColumn
from dbo.MyTable
join anotherDB.dbo.OtherTable ot
on MyTable.KeyColumn = ot.KeyColumn

This is MSSQL proprietary syntax, but the ANSI syntax would need a subquery,
and as you found, ntext columns are not allowed in subqueries.

Simon
Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: shottarum | last post by:
I currently have 2 tables as follows: CREATE TABLE . ( mhan8 int, mhac02 varchar(5), mhmot varchar(5), mhupmj int )
12
by: jimserac | last post by:
I had previously posted this in an Access forum with negative results so will try here. Although this question specifies an Access database, I also wish to accomplish this with a large MS SQL...
2
by: Mike Leahy | last post by:
Hello all, This question is related to updating tables - is there any way to calculate or update the values in a column in a table to the values in a field produced by a query result? An...
16
by: robert | last post by:
been ruminating on the question (mostly in a 390/v7 context) of whether, and if so when, a row update becomes an insert/delete. i assume that there is a threshold on the number of columns of the...
2
by: Miro | last post by:
I will ask the question first then fumble thru trying to explain myself so i dont waste too much of your time. Question / Statement - Every mdb table needs a PrimaryKey ( or maybe an index - i...
4
by: kdpo | last post by:
Could someone tell where I can find out if it's true that during UPDFATE SQL Serve deletes data from table, and then inserts new one. Thanks -A
22
by: tonialbrown | last post by:
I have an Sql update statement that I am using that updates the data from a record chosen by the user from a list box lstDelFrom. This is working for all the text fields & updates fine. Once I add...
3
by: Michel Esber | last post by:
Hi all, DB2 V8 LUW FP 15 There is a table T (ID varchar (24), ABC timestamp). ID is PK. Our application needs to frequently update T with a new value for ABC. update T set ABC=? where ID...
2
by: BobLewiston | last post by:
Some of you may have seen my earlier thread “PasswordHash NULL problem”. I’ve started a new thread because investigation has shown that the problem is actually quite different than I previously...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.