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)
5 5791
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 - update Mapping set SID = SMappingID where SMappingID is not null;
pbmods 5,821
Recognized Expert Expert
Heya, NamelessNumberh eadMan.
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: - 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.
Heya, NamelessNumberh eadMan.
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: - 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 NamelessNumberh eadMan didn't you?
You just wanted to say NamelessNumberh eadMan 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
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.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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 to
another table B's long column.
Unfortunately, "insert into table_a select long_column from table_b"
doesn't work. I also thought of changing table_a's long column to clob,
|
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
|
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" ALMOST works ... unfortunately it adds the data at the
END of Column B ... and I need Column B to be an exact replica of
Column A (but with a different name of course).
Right now I have my users doing it manually, but I really want to
automate it...
|
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 this is also editable.
The user can enter text in the column or rich text box.
If I press CTRL C in this datagrid column, followed by CTRL V to copy the
string to another record, I get a pile of junk pasted prior to the string i
copied
eg The...
|
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 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...
| |
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 DataTable.
Anyone can help me?
|
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 method
available to do a copy of one column?
Thanks!
|
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 been searching for code for each part of the task separately and trying to piece together multiple macros, that do something similar, to what I’m trying to accomplish in my over all task, but I’m not having a lot of luck. So, here’s the entire task,...
|
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 query which is incorrect:
UPDATE PARTNER
SET VEND=
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |