Drop Table
Support Forum for database administrators and web based access to important newsgroups related to databasesHi 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
Post Follow-up to this messageUpdate 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
Post Follow-up to this messageYou 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
Post Follow-up to this messageYou are both SQL Stalions! I knew it would be simple! Thank you - you've been a great help Kindest Regards Simon
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread