473,379 Members | 1,302 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

copy one column to another

I have a table I need to make changes to. Dropping columns isn't my problem, but before I drop one of the columns I need to copy the values that aren't null to another existing column in the same table. So for psuedo-code it would be something like:

update Mapping Set SID = (select SMappingID from Mapping where SMappingID is not null)

I don't know if I should be doing this in a loop (which I'm not totally familiar with using) or if there is a better way to copy these values. If it helps my columns are -

ID (int, Not Null, PK)
SID (int, Not Null, FK)
PartID (int, Not Null, FK)
CompID (int, Not Null)
SMappingID (int, Null)
Jul 2 '07 #1
5 5774
r035198x
13,262 8TB
I have a table I need to make changes to. Dropping columns isn't my problem, but before I drop one of the columns I need to copy the values that aren't null to another existing column in the same table. So for psuedo-code it would be something like:

update Mapping Set SID = (select SMappingID from Mapping where SMappingID is not null)

I don't know if I should be doing this in a loop (which I'm not totally familiar with using) or if there is a better way to copy these values. If it helps my columns are -

ID (int, Not Null, PK)
SID (int, Not Null, FK)
PartID (int, Not Null, FK)
CompID (int, Not Null)
SMappingID (int, Null)
Which one do you want to copy into which one?
If you're copying SMappingID into SID then you can do
Expand|Select|Wrap|Line Numbers
  1. update Mapping set SID = SMappingID where SMappingID is not null;
Jul 2 '07 #2
pbmods
5,821 Expert 4TB
Heya, NamelessNumberheadMan.

Your code attempts to set multiple values to a single column (all the values that are not null get saved into each row).

You can do this:
Expand|Select|Wrap|Line Numbers
  1. INSERT INTO `Mapping` (`SID`) SELECT `SMappingID` FROM `Mapping` WHERE `SMappingID` IS NOT NULL
Tell us a bit more about what you're trying to accomplish.
Jul 2 '07 #3
r035198x
13,262 8TB
Heya, NamelessNumberheadMan.

Your code attempts to set multiple values to a single column (all the values that are not null get saved into each row).

You can do this:
Expand|Select|Wrap|Line Numbers
  1. INSERT INTO `Mapping` (`SID`) SELECT `SMappingID` FROM `Mapping` WHERE `SMappingID` IS NOT NULL
Tell us a bit more about what you're trying to accomplish.
You just wanted to say NamelessNumberheadMan didn't you?
Jul 2 '07 #4
You just wanted to say NamelessNumberheadMan didn't you?
Appolgies for any lack in clarity. I need to copy SMappingID to SID where SMappingID is not null. Then I need to drop the SMappingID column. I'm no DB expert, and was under the impression this would be more complex and require a loop with IFs and Cases. I haven't had the chance to try out the solution yet, but I'll let you know if/when it works.

- Thanks
Jul 3 '07 #5
r035198x
13,262 8TB
Appolgies for any lack in clarity. I need to copy SMappingID to SID where SMappingID is not null. Then I need to drop the SMappingID column. I'm no DB expert, and was under the impression this would be more complex and require a loop with IFs and Cases. I haven't had the chance to try out the solution yet, but I'll let you know if/when it works.

- Thanks
No need for apologies. I just think that your user name is e-r original.
Jul 3 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: jcwhui | last post by:
Hello all, Yes, it is another Oracle 8.0 question. We are just too small to force our customer to migrate to newer Oracle. My problem is I need to copy the value of the long column in table A...
1
by: Bill | last post by:
I have a column of digits I'd like to copy into another column in the same table. How would I do this? Thanks, Bill
3
by: Melissa Kay Beeline | last post by:
This is driving me crazy!! I'm using MSACCESS, and all I want to do is create a macro/query/anything that will take the data in Column A and copy it into Column B (same table) "Insert into"...
1
by: SeeSharp Bint | last post by:
I have a form with a datagrid containing 3 columns linked to an in memory dataset. Only the 3rd column is editable. Beneath that I have a rich text box bound to the same data as the 3rd column and...
2
by: NamelessNumberheadMan | last post by:
I have a table I need to make changes to. Dropping columns isn't my problem, but before I drop one of the columns I need to copy the values that aren't null to another existing column in the same...
3
by: Manuel | last post by:
Hi to all, I'm trying to copy a Datacolumn from a table to another, but with this code: destTable.Columns.Add(srcTable.Column); I got this error: Column 'colname' already belongs to another...
1
by: Soulless | last post by:
Hi, I have a datagrid with multiple columns and would like to copy the contents of one column to another datagrid object that only has the one column. I don't think copy can do this. Is there a...
0
by: Taxman | last post by:
Windows XP, MS Office Excel 2003 If the tasks, I’m trying accomplish have been addressed previously (separately or in combination). Please, provide the links or keyword search to find them. I’ve...
7
by: himanshupancholi | last post by:
Hi, I need to Copy all values of a column from one table to another. Below are the details: Source: STL_GRP table, VEND column Destination PARTNER table, VEND column. I am using the below...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.