I want to use Group_ID as the primary key in all of my tables. Unfortunately, the uploaded data has group IDs from two systems: OLD_ID and NEW_ID. Ultimately, all groups will have a NEW_ID number, but for now, some do and some don't. This means that some groups only have OLD_ID, some have both NEW_ID and OLD_ID, and some only have NEW_ID.
What I want to do is pull the information from NEW_ID and OLD_ID into a new field in a separate table, GROUP_ID (the new field is also called Group_ID). The logic I want goes like this: IF NEW_ID is not blank, use NEW_ID; ELSE use OLD_ID.
In the original table, there would be no primary key, since both OLD_ID and NEW_ID have null values in some records. Both of these fields would link to primary key Group_ID in the GROUP_ID table, and all other tables would link to Group_ID via that table as well.
My restrictions are that I can't change anything in the uploaded data, and that I only want to pull up one of the ID numbers (in the event that a group has both).
My questions:
(1) Is this possible to do?
(2) If it is possible, what is the SQL code and where would I put it?
(3) If it is not possible, are there other solutions?
5 1241 NeoPa 32,556
Expert Mod 16PB
If the data you intend to upload doesn't already contain a [GROUP_ID] value, then this could not be uploaded directly into place. However, with the logic you posted, and always assuming that all records must have one or the other, the data could be uploaded into a holding table, then transferred from there using the specified logic.
The SQL for transferring the data would be similar to : - INSERT INTO [MainTable] ( {Field List} )
-
-
SELECT Nz([NEW_ID],[OLD_ID]) AS [Group_ID],
-
*
-
-
FROM [HoldingTable]
Don't forget to delete any data from the holding table that has been successfully transferred.
Welcome to Bytes!
I must ask: is this the only option available to me? I ask because I would prefer not to combine all the OLD_ID and NEW_ID values into one field, as some groups have both and this would cause them to have duplicate records. Ideally, I want only the NEW_ID, unless it doesn't exist, and only then would I take the OLD_ID.
NeoPa 32,556
Expert Mod 16PB
What I posted gives you : - [Group_ID] set to the value of [NEW_ID] if it has a value otherwise [OLD_ID] if not.
- All other original fields, presumably including both [OLD_ID] and [NEW_ID], regardless of what data they may, or may not, contain.
It seems from your question that you didn't appreciate this. If you did, then I don't quite understand your question, but will happily check back if you wish to clarify.
Sorry, I don't really understand SQL. Thank you for your clarification; I will try the code and see if I can get it right.
NeoPa 32,556
Expert Mod 16PB
Let us know if you struggle.
Post the SQL you try if it fails.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Greg Lindstrom |
last post by:
Hello-
I have created a class, FixedLengthRecord.py, that allows me to manipulate
fixed length records in the routines I write. I recently converted it to
read record layouts from an SQL server...
|
by: Michael Walton |
last post by:
I am trying to write some code that inserts or updates a text field in my
SQL Server 2000 database. The SQL statement is created using a submit from
a form, and the text is coming from a...
|
by: Don Stefani |
last post by:
Hello,
I have a form that I want to submit "onchange", OK I've got that working, but when the
form submits, I want to pass along a value to a CGI script, as if that value was in a
hidden form...
|
by: phpuser32423 |
last post by:
Hi everyone
Is it by any chance possible to use mysql and php to auto create the
content for drop-down lists on forms by retrieving the values from a
database? The reason i ask is that on a site...
|
by: Iain Miller |
last post by:
Now this shouldn't be hard but I've been struggling on the best way as to
how to do this one for a day or 3 so I thought I'd ask the assembled
company.....
I'm writing an application that tracks...
|
by: John young |
last post by:
I have been looking for an answer to a problem and have found this
group and hope you can assist .
I have been re doing a data base I have made for a car club I am with
and have been trying to...
|
by: ND |
last post by:
I need to create a separate field from 4 fields, "street address", "city",
"State" and "zip code". For example,
Street address - 100 Forest Street
City - Seattle
State - WA
Zip - 05555
...
|
by: The Frog |
last post by:
Hello everyone,
I am working on an application that can build database objects in MS
Access from text files. I suppose you could call it a backup and
restore type routine.
Accessing the...
|
by: Ecohouse |
last post by:
I have a main form with two subforms. The first subform has the child
link to the main form identity key.
subform1 - Master Field: SK
Child Field: TrainingMasterSK
The second subform has a...
|
by: adwest |
last post by:
Forgive me if this is a foolish question. I "play" in Access and have only created a few rather simple relational databases. My knowledge and experience is limited. I have no formal training, just...
|
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...
|
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...
|
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...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
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
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
| |