Drop Table

Support Forum for database administrators and web based access to important newsgroups related to databases
Register on Database Support Forum Edit your profileCalendarFind other Database Support forum membersFrequently Asked QuestionsSearch this forum -> 
For Database admins: Free Database-related Magazines Now Free shipping to Texas


Post New Thread










Thread
Author

Appending from one column to another for every row in a table
Hi there,

I need to carry out a database cleaning/maintenance operation whereby I
take the text in one column called ShortDescription and add it to the
text in a column called AdditionalDetails.

I know how to copy from one to the other but that would have the effect
of overwriting the values in the AdditionalDetails column. I need
whatever is in the first column to be simply appended to whatever is in
the second. If the first has null in it, nothing should happen, and I
guess if the second has a null in it, the null should be replaced with
whatever's in the second column.

Can anyone advise me on how to do this? I'm sure it must be a relatively
simple operation but I've never seen it done.

Thanks to anyone who can help

Simon

Report this thread to moderator Post Follow-up to this message
Old Post
Simon Harvey
12-14-06 12:12 AM


Re: Appending from one column to another for every row in a table
Update table1 set additionaldetails =  isnull(additionaldet
ails,'') +
shortdescription
where shortdescription is not null


Jay

Simon Harvey  wrote:
> Hi there,
>
> I need to carry out a database cleaning/maintenance operation whereby I
> take the text in one column called ShortDescription and add it to the
> text in a column called AdditionalDetails
>
> I know how to copy from one to the other but that would have the effect
> of overwriting the values in the AdditionalDetails column. I need
> whatever is in the first column to be simply appended to whatever is in
> the second. If the first has null in it, nothing should happen, and I
> guess if the second has a null in it, the null should be replaced with
> whatever's in the second column.
>
> Can anyone advise me on how to do this? I'm sure it must be a relatively
> simple operation but I've never seen it done.
>
> Thanks to anyone who can help
>
> Simon


Report this thread to moderator Post Follow-up to this message
Old Post
Jay
12-14-06 12:12 AM


Re: Appending from one column to another for every row in a table
You need concatenation, which is implemented using the + character.

UPDATE
SET AdditionalDetails = AdditionalDetails + ShortDescription
WHERE ShortDescription IS NOT NULL

The problem with the query above is that if AdditionalDetails is NULL
the concatenation ends up as NULL.  So the more robust version would
be:

UPDATE
SET AdditionalDetails =  COALESCE(AdditionalD
etails, '') +
ShortDescription
WHERE ShortDescription IS NOT NULL

Roy Harvey
Beacon Falls, CT

On Wed, 13 Dec 2006 16:20:40 +0000, Simon Harvey
<nothanks@hotmail.com> wrote:

>Hi there,
>
>I need to carry out a database cleaning/maintenance operation whereby I
>take the text in one column called ShortDescription and add it to the
>text in a column called AdditionalDetails.
>
>I know how to copy from one to the other but that would have the effect
>of overwriting the values in the AdditionalDetails column. I need
>whatever is in the first column to be simply appended to whatever is in
>the second. If the first has null in it, nothing should happen, and I
>guess if the second has a null in it, the null should be replaced with
>whatever's in the second column.
>
>Can anyone advise me on how to do this? I'm sure it must be a relatively
>simple operation but I've never seen it done.
>
>Thanks to anyone who can help
>
>Simon

Report this thread to moderator Post Follow-up to this message
Old Post
Roy Harvey
12-14-06 12:12 AM


Re: Appending from one column to another for every row in a table
You are both SQL Stalions!

I knew it would be simple!

Thank you - you've been a great help

Kindest Regards

Simon

Report this thread to moderator Post Follow-up to this message
Old Post
Simon Harvey
12-14-06 10:25 AM


Sponsored Links





Last Thread Next Thread
Post New Thread

MS SQL Server archive

Show a Printable Version Email This Page to Someone! Receive updates to this thread
Microsoft SQL Server
Access database support
PostgreSQL Replication
SQL Server ODBC
FoxPro Support
PostgreSQL pgAdmin
SQL Server Clustering
MySQL ODBC
Web Applications with dBASE
SQL Server CE
MySQL++
Sybase Database Support
MS SQL Full Text Search
PostgreSQL Administration
SQL Anywhere support
DB2 UDB Database
Paradox Database Support
Filemaker Database
Berkley DB
SQL 2000/2000i database
ASE Database
Forum Jump:
All times are GMT. The time now is 09:52 PM.

 
Mobile devices forum | Database support forum archive




Copyrights DropTable.com Database Support Forum 2004 - 2006