Tuesday, March 20, 2012

Copying one text column to another

Hi All
I have to copy text data from a table in one database to a table in a
different database, both table reside on the same server.
I tried two options which didn't work (see code below), and will be more
than gratefull for any help.
Thanks
Elie Grouchko
***************************************
I tried the following (didn't work):
UPDATE database2.dbo.table2
SET textcolumn2 = (SELECT database1.dbo.textcolumn1 FROM table1 WHERE
tablekey1 = @.tablekey1)
WHERE tablekey2 = @.tablekey2
***************************************
I also tried (also didn't work):
Select @.textcolumn1ptr = TextPtr(textcolumn1) FROM database1.dbo.table1
WHERE tablekey1 = @.tablekey1
Select @.textcolumn2ptr = TextPtr(textcolumn2) FROM database2.dbo.table2
WHERE tablekey2 = @.tablekey2
UpdateText
database2.dbo.table2.textcolumn2 @.textcolumn2ptr
Null
0
database1.dbo.table1.textcolumn1 @.textcolumn1ptrElie,
I think this will do what you want:
update database2.dbo.table2 set
textcolumn2 = T1.textcolumn1
from database1.dbo.table1 as T1
where T1.tablekey1 = database2.dbo.table2.tablekey2
and database2.dbo.table2.tablekey2 = @.tablekey2
Steve Kass
Drew University
Elie Grouchko wrote:

>Hi All
>I have to copy text data from a table in one database to a table in a
>different database, both table reside on the same server.
>I tried two options which didn't work (see code below), and will be more
>than gratefull for any help.
>Thanks
>Elie Grouchko
>***************************************
>I tried the following (didn't work):
> UPDATE database2.dbo.table2
> SET textcolumn2 = (SELECT database1.dbo.textcolumn1 FROM table1 WHERE
>tablekey1 = @.tablekey1)
> WHERE tablekey2 = @.tablekey2
>***************************************
>I also tried (also didn't work):
> Select @.textcolumn1ptr = TextPtr(textcolumn1) FROM database1.dbo.table1
> WHERE tablekey1 = @.tablekey1
> Select @.textcolumn2ptr = TextPtr(textcolumn2) FROM database2.dbo.table2
> WHERE tablekey2 = @.tablekey2
> UpdateText
> database2.dbo.table2.textcolumn2 @.textcolumn2ptr
> Null
> 0
> database1.dbo.table1.textcolumn1 @.textcolumn1ptr
>
>|||Great, it works
Thanks
:)
"Steve Kass" <skass@.drew.edu> wrote in message
news:%23V4SREbIFHA.2740@.TK2MSFTNGP12.phx.gbl...
> Elie,
> I think this will do what you want:
> update database2.dbo.table2 set
> textcolumn2 = T1.textcolumn1
> from database1.dbo.table1 as T1
> where T1.tablekey1 = database2.dbo.table2.tablekey2
> and database2.dbo.table2.tablekey2 = @.tablekey2
> Steve Kass
> Drew University
> Elie Grouchko wrote:
>sql

No comments:

Post a Comment