Results 1 to 6 of 6
  1. #1
    Join Date
    Jul 2007
    Posts
    3

    Unanswered: How to convert varchar datatype to int??

    Hi all,

    I am using a varchar datatype for PIN number to handle zero at start. Now i want to do mathematical calculation to encrypt the PIN so i need to convert that varchar datatype to int so that zero should not be discarted after conversion. i.e. 0123 and 123 must not be treated as same PIN.

    Please kindly give me a way out. I am using RSA encryption.

    Thanks in anticipation.

    Haider Abbas.

  2. #2
    Join Date
    May 2007
    Location
    somewhere in dbforums
    Posts
    221
    well if you convert the varchar into int, int data type will always ignore the leading zero...so an integer data type will treat 0123 and 123 as similar.....because numerically both the values are the same....
    Last edited by nick.ncs; 07-02-07 at 06:58.

  3. #3
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    An alternative method would be to find out the ASCII code (integer value) for each character.
    You can then use the CHAR() function to translate this back.
    Code:
    SELECT ASCII('0'), CHAR(48)
    SELECT ASCII('A'), CHAR(65)
    Last edited by gvee; 07-02-07 at 07:27.
    George
    Home | Blog

  4. #4
    Join Date
    May 2004
    Location
    Seattle
    Posts
    1,313
    what sort of encryption are you doing that requires the value to be int? there are plenty of ways to encrypt strings...

  5. #5
    Join Date
    Jan 2003
    Location
    Massachusetts
    Posts
    5,799
    Provided Answers: 11
    Can you use a numeric datatype, so leading 0's become significant? i.e. instead of 0123 have .0123?

  6. #6
    Join Date
    Jul 2007
    Posts
    3

    Re: How to convert varchar datatype to int??

    Quote Originally Posted by georgev
    An alternative method would be to find out the ASCII code (integer value) for each character.
    You can then use the CHAR() function to translate this back.
    Code:
    SELECT ASCII('0'), CHAR(48)
    SELECT ASCII('A'), CHAR(65)
    Hi georgev..

    Thanx alot... thats what i wanted...!!
    Actually i've taken each character of PIN through substring function and converted it to ASCII integer. Each character is encrypted separately.

    Thanx alot to others too..!!

    Haider.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •