[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 368
  • Last Modified:

create constant unique ID from three columns

I have a large contact table that gets refreshed every quarter.  I am trying to assign a unique identifier to the field that, unlike newid(), will remain constant with updates. I know I can build a string from things like firstname, lastname, address,city, state, zip, but what would be the best way to convert that string concatenation into an identifier that will be constant with every update (I know when people move it will change the id, but that is not of concern for me right now).

Thanks for the help.
0
gwarcher
Asked:
gwarcher
1 Solution
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Give us a before-and-after data mockup of what you're trying to pull off here, with emphasis on any variation in 'every update'.
0
 
Paul MacDonaldDirector, Information SystemsCommented:
You could use a unique number aside from the ID (which, i presume, you think will change between database moves).  Create an integer column (let's call it UniqID) and seed it with values from whatever ID column exists now.  

Then create a process where you get MAX(UniqID) + 1 and insert that value into the column whenever you add a new record.  The number will always be unique, even after a database move.  Your only worry is if there's a great deal of sudden activity when adding new records.
0
 
gwarcherAuthor Commented:
ok I will clarify a little more, lets say I have the following

firstname   lastname      idnumber
robert         smith           12345
jane            doe               54321

I can't use the idnumber in all cases as the uniqueID because the data I get will sometimes have errors in it where there will be a duplicate idnumber.  I catch those later but for purposes of parsing through the data I would like to combine the firstname, lastname and idnumber columns to create a unique id that will carry over with each quarterly update.

thanks,
0
 
gwarcherAuthor Commented:
will the hashbyte function be sufficient in doing this?
0
 
Anthony PerkinsCommented:
will the hashbyte function be sufficient in doing this?
Not really.  If the data is duplicated, using the HASHBYTE() function will simply give you the same value each time.
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now