473,385 Members | 1,311 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,385 software developers and data experts.

Creating a key field from selective data in other fields -- is it possible?

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?
Apr 15 '10 #1
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 :
Expand|Select|Wrap|Line Numbers
  1. INSERT INTO [MainTable] ( {Field List} )
  2.  
  3. SELECT      Nz([NEW_ID],[OLD_ID]) AS [Group_ID],
  4.             *
  5.  
  6. FROM        [HoldingTable]
Don't forget to delete any data from the holding table that has been successfully transferred.

Welcome to Bytes!
Apr 15 '10 #2
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.
Apr 15 '10 #3
NeoPa
32,556 Expert Mod 16PB
What I posted gives you :
  1. [Group_ID] set to the value of [NEW_ID] if it has a value otherwise [OLD_ID] if not.
  2. 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.
Apr 15 '10 #4
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.
Apr 15 '10 #5
NeoPa
32,556 Expert Mod 16PB
Let us know if you struggle.

Post the SQL you try if it fails.
Apr 15 '10 #6

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

Similar topics

2
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...
16
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...
1
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...
2
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...
2
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...
3
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...
5
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 ...
17
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...
9
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...
2
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...
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
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: 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,...
0
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...
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
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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.