Professional Web Applications Themes

Calculating a unique hash on 4 columns in T-SQL? - Microsoft SQL / MS SQL Server

Is there a way to calculate a unique hash value based on the combination of 4 column values (two Nvarchar and two Int)? I attempted to calculate a hash in T-SQL for the combination of 4 columns by concatenating the 4 column values in a string and then calculating the CHECKSUM on the string but CHECKSUM ignores some characters (The apostrophe ' and the dash "-"). There are other problems with content and order of the columns when values are null or null strings. Any help would be greatly appreciated. Thanks,...

  1. #1

    Default Calculating a unique hash on 4 columns in T-SQL?

    Is there a way to calculate a unique hash value based on the combination of
    4 column values (two Nvarchar and two Int)?


    I attempted to calculate a hash in T-SQL for the combination of 4 columns by
    concatenating the 4 column values in a string and then calculating the
    CHECKSUM on the string but CHECKSUM ignores some characters (The apostrophe
    ' and the dash "-"). There are other problems with content and order of the
    columns when values are null or null strings.

    Any help would be greatly appreciated.

    Thanks,


    Steven Guest

  2. #2

    Default Re: Calculating a unique hash on 4 columns in T-SQL?

    a hash is not unique by nature, if it were, it would be called a key. It
    seems like your approach should work if you're really going after a hash.

    ----------------------------------------------------
    The views expressed here are my own
    and not of my employer.
    ----------------------------------------------------
    "Steven" <com> wrote in message
    news:#phx.gbl... 
    of 
    by 
    apostrophe 
    the 


    Kevin Guest

  3. #3

    Default Re: Calculating a unique hash on 4 columns in T-SQL?

    FYI:

    checksum(col1, col2, col3, col4)

    FYI:

    This:

    select checksum('ab'),checksum('a-b'), checksum('a''b')

    says:

    2159 35935 36095

    Bye,
    Delbert Glass

    "Steven" <com> wrote in message
    news:#phx.gbl... 
    of 
    by 
    apostrophe 
    the 


    Delbert Guest

Similar Threads

  1. Unique Form inserting into many tables using unique id
    By Gabo Navarro in forum Macromedia Exchange Dreamweaver Extensions
    Replies: 0
    Last Post: September 16th, 06:25 PM
  2. Replies: 5
    Last Post: December 12th, 10:29 PM
  3. Generating unique values for TEXT columns
    By Frank D. Engel, Jr. in forum PostgreSQL / PGSQL
    Replies: 6
    Last Post: January 3rd, 06:39 PM
  4. Replies: 16
    Last Post: September 12th, 09:02 PM
  5. calculating unique letters in string
    By Patrick in forum FileMaker
    Replies: 2
    Last Post: July 13th, 10:47 AM

Bookmarks

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139