SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 new ID column design help
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Hommer
Aged Yak Warrior

771 Posts

Posted - 07/31/2013 :  15:26:24  Show Profile  Reply with Quote
Hi,

I want to get some advices on how to deal with this.

I need to periodically send a set of data to a vendor. They need to have a column what is an unique identifyer but they cannot handle 16 digit GUI.

So I have this my_old_person table with person_GUI as uniqueidentifier. It got 200K rows in it.

I am thinking creating a staging utility table:

Create table my_new_person
(person_GUI varchar(255) not null,<--this will contains the same GUI from the old
Person_ID nvarchar(20))<--send tis to vendor

At the beginning of my nightly ETL, I will run this to get the new data:

Insert into my_new_person
select a.person_GUI, xyz
from my_old_person a join my_new_person b
on a.person_GUI=b.person_GUI
where not exists (Select person_GUI from my_old_person)

How do I implement this person_ID to make it unique and populate correctly in above xyz?

Thanks!

James K
Flowing Fount of Yak Knowledge

3334 Posts

Posted - 07/31/2013 :  15:35:20  Show Profile  Reply with Quote
You could make the Person_ID an int and make it an identity colum like so:
CREATE TABLE my_new_person
(
  person_GUI VARCHAR(255) NOT NULL , 
  Person_ID NVARCHAR(20) NOT NULL IDENTITY(1,1)
)
I didn't quite follow the script that you want to run at the beginning of your nightly ETL. Is the goal to insert any new persons that are in the my_old_person table to my_new_Person_table? If so, and if you do the IDENTITY column that I proposed above, you would do this:
INSERT  INTO my_new_person (person_GUI)
SELECT  a.person_GUI
FROM    my_old_person a
WHERE   NOT EXISTS ( SELECT person_GUI
                     FROM   my_new_person )
Go to Top of Page

Hommer
Aged Yak Warrior

771 Posts

Posted - 07/31/2013 :  15:59:30  Show Profile  Reply with Quote
Great, thanks!

Identity!
Go to Top of Page

James K
Flowing Fount of Yak Knowledge

3334 Posts

Posted - 07/31/2013 :  16:05:03  Show Profile  Reply with Quote
You are welcome! Unfortunately, the update script that I posted is just plain wrong. You need this:
INSERT  INTO my_new_person (person_GUI)
SELECT  a.person_GUI
FROM    my_old_person a
WHERE   NOT EXISTS ( SELECT *
                     FROM   my_new_person b
                     WHERE b.person_GUI = a.Person_GUI )

Edited by - James K on 07/31/2013 16:05:19
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52249 Posts

Posted - 08/01/2013 :  03:12:33  Show Profile  Reply with Quote
Also


INSERT  INTO my_new_person (person_GUI)
SELECT  a.person_GUI
FROM    my_old_person a
EXCEPT
SELECT b.person_GUI
FROM   my_new_person b



------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

Hommer
Aged Yak Warrior

771 Posts

Posted - 08/05/2013 :  11:49:18  Show Profile  Reply with Quote
Actually, I implemented this one:

INSERT INTO my_new_person (person_GUI)
SELECT a.person_GUI
FROM my_old_person a
LEFT JOIN my_new_person b on a.GUI=b.GUI
Where b.GUI is null

Neverthless, thanks for both of you!

Go to Top of Page

James K
Flowing Fount of Yak Knowledge

3334 Posts

Posted - 08/05/2013 :  11:52:36  Show Profile  Reply with Quote
That is just as good - probably better performing as well, although I am making a wild guess there. Regardless, now you know at least 3 ways to skin that cat!
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000