Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 need to merge 3 fields & then delete 2 of them

Author  Topic 

10Dawg
Starting Member

46 Posts

Posted - 2011-08-25 : 13:51:04
I have 3 custom fields in the same table (End Doc#26, End Doc#8, and EndDoc#10). I want to put any data in #26 & #8 into #10 so I can delete #26 & #8. The table is called dbo.CustomFields.

10Dawg

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2011-08-25 : 15:59:38
What are the data types of the columns? Are they the same or different?

What are the rules for merging (such as appending them in any order, or in specific order etc.)

Assuming they are all varchars, and that you want to append them in any order, and that the length of the combined data does not exceed the size of the EndDoc#10 column, you can do this:
UPDATE dbo.CustomFields SET [EndDoc#10] =
COALESCE([EndDoc#10],'') +
COALESCE([Doc#8],'') +
COALESCE([Doc#26],'')
Once you are completely satisfied with the results in the EndDoc#10 column, you can remove the other two columns using:
ALTER TABLE dbo.CustomFields DROP COLUMN [Doc#8],[Doc#26];
Go to Top of Page

10Dawg
Starting Member

46 Posts

Posted - 2011-08-25 : 16:13:12
yes all your assumptions are true. Thanks for the code.

10Dawg
Go to Top of Page
   

- Advertisement -