If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Microsoft SQL Server > Copying NTEXT data from one record to another

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-01-10, 12:22
tcarnahans tcarnahans is offline
Registered User
 
Join Date: Sep 2010
Posts: 6
Question Copying NTEXT data from one record to another

I tried seaching the archive without much success, so here is my situation.

I have a SS2K database.

I have a table (MyTable) with one NTEXT field (MyNtext) and a prime key (PK). and I need to copy data from the NTEXT field in one record to the same field in another record and overwrite the data.

I tried using:

Code:
UPDATE MyTable
SET MyNtext = (SELECT MyNtext FROM MyTable WHERE PK = 44)
WHERE PK = 66
I get the error code:

Quote:
.Net SqlClient Dataq Provider: Msg 279, Level 16, State 3, Line 40
The ntext data type is invalid in the subqquery or aggregate expression.
I tried playing around with READTEXT and WRITETEXT, but I don't know how to get the output from the READTEXT to feed the input of the WRITETEXT.

Does anyone have an example of how to do this? Any help would be appreciated!
Reply With Quote
  #2 (permalink)  
Old 09-01-10, 12:42
Wim Wim is offline
Registered User
 
Join Date: Nov 2004
Posts: 1,160
This worked in MSSQL 2008:
Code:
DROP TABLE MyTable
CREATE TABLE MyTable (
	pk int NOT NULL,
	mytext NTEXT
)
INSERT INTO MyTable (pk, mytext) VALUES (44, 'kklkl')
INSERT INTO MyTable (pk, mytext) VALUES (66, 'blabla')

UPDATE MyTable
SET Mytext = (SELECT Mytext FROM MyTable WHERE PK = 44)
WHERE PK = 66

select * from MyTable
__________________
With kind regards . . . . . SQL Server 2000/2005/2008/2008 R2 Earned beers: 13
Wim
Beware of bugs in the above code; I have only proved it correct, not tried it. -- Donald Knuth
Grabel's Law: 2 is not equal to 3 -- not even for very large values of 2.
Pat Phelan's Law: 2 very definitely CAN equal 3 -- in at least two programming languages

Last edited by Wim; 09-01-10 at 12:49. Reason: Reread question.
Reply With Quote
  #3 (permalink)  
Old 09-01-10, 12:56
Wim Wim is offline
Registered User
 
Join Date: Nov 2004
Posts: 1,160
This works too:
Code:
UPDATE MyTable
SET MyTable.Mytext = Src.mytext
FROM MyTable, MyTable as Src
WHERE MyTable.PK = 66 AND
	Src.PK = 44
__________________
With kind regards . . . . . SQL Server 2000/2005/2008/2008 R2 Earned beers: 13
Wim
Beware of bugs in the above code; I have only proved it correct, not tried it. -- Donald Knuth
Grabel's Law: 2 is not equal to 3 -- not even for very large values of 2.
Pat Phelan's Law: 2 very definitely CAN equal 3 -- in at least two programming languages
Reply With Quote
  #4 (permalink)  
Old 09-01-10, 13:19
tcarnahans tcarnahans is offline
Registered User
 
Join Date: Sep 2010
Posts: 6
Thumbs up Thanks

It worked!

I am not sure why the other did not work.

Many thanks! You are an angel
Reply With Quote
Reply

Tags
ntext, t-sql

Thread Tools
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 On
Pingbacks are On
Refbacks are On