Is there a way to convert an alphanumeric string in a vchar field to a unique integer value. The string could contain alpha,numbers,'.','-','_',etc..... ????
And how would you determine what the number should be based on the existing data? Give us a sample of the existing values and the values you would like them converted to.
It doesn't matter what the integer value is -- it just needs to be unique and the algorithm shoulod always translate the same string to the same integer value..
I don;t understand what you nmena when you say it must always translate the same string to the same integer at the same time you say every value must be uniwue. This is a contradiction in terms.
Good answer DBomrrsm except he says he wants it to be unique, so you need to use a function that converts the ascii values of each letter, i.e. the hex value of the entire string! Or zip the string and take its hex value.
-Karl
[red] Cursors, triggers, user-defined functions and dynamic SQL are an axis of evil![/red]
[green]Life's uncertain...eat dessert first...www.deerfieldbakery.com[/green]
so do you need the function to convert the passed string to the same integer all the time or if it is passed again does it have to generate a unique integer - so different from the last time it was passed.
it should generate the same integer all the time. I.e. the string would always convert to the same integer. AND a different string would never convert to that integer.
Ahh, I was being a bit facetious. How long can the string be? Big integers are 8 bytes, so you'd only be able to convert 8-byte strings unless you did some really esoteric coding to eliminate unneeded ascii values.
Then of course you could go really crazy and build your own big-big integers. But the real question is what are you really trying to do with this?
-Karl
[red] Cursors, triggers, user-defined functions and dynamic SQL are an axis of evil![/red]
[green]Life's uncertain...eat dessert first...www.deerfieldbakery.com[/green]
I'm thinking the most straightforward way to do this is with a lookup table that contains the possible strings and an identity field. When a new string is added to the main table, you could have an insert/update trigger which adds iot to the lookup table before looking up the value to store in the table. The trigger would also use the lookup table to convert records where the existing string was alread in it.
we are really trying to create an interger key equilvalent into a legacy system that for some wierd reason only accepts integers in a field that is deeply entrenched in numerous applications.
SQLSister to the rescue...the St. Bernard of TT.
-Karl
[red] Cursors, triggers, user-defined functions and dynamic SQL are an axis of evil![/red]
[green]Life's uncertain...eat dessert first...www.deerfieldbakery.com[/green]
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.