Results 1 to 10 of 10
  1. #1
    Join Date
    Jun 2004
    Posts
    4

    Unanswered: checksums and data types

    I'm creating a checksum column in a table that is to be calculated over several columns within the table.

    One of the columns to be included in the checksum formula has a data type ntext.

    But on trying to complete this new table design (or similarly using alter table in QA) - both return an error stating that the data type is invalid for the checksum function.

    This happens for both ntext and text data types.

    Can anyone tell me if there is a way round this without having to change the data type - or the valid data types that can be used for the checksum funciton?

    Also reasons why would be helpful!

    Thanks

  2. #2
    Join Date
    Jun 2004
    Posts
    4
    please ignore - http://www.dbforums.com/t989557.html shows this not to be possible....

    nevermind

  3. #3
    Join Date
    Nov 2004
    Location
    on the wrong server
    Posts
    8,835
    Provided Answers: 6
    you might want to try something like so:

    SELECT checksum(col1,col2,CAST(CAST(col3 as varchar(1)) as int))
    FROM testTable

    I am not sure if this totally works. Text and Ntext are meant to hold large amounts of text data like notes field in a customer service application. There is no implicit data conversion between int and ntext\text in sql server because that is just one of the rules and it would'nt make much since do so. To tell the truth it sounds like your problem is a design issue. However you can explicitly convert data types as shown above but please keep in mind if you try to cast character data in col3 above to an int, you will recieve an error. So you might have to add an IsNumeric in there as well.
    “If one brings so much courage to this world the world has to kill them or break them, so of course it kills them. The world breaks every one and afterward many are strong at the broken places. But those that will not break it kills. It kills the very good and the very gentle and the very brave impartially. If you are none of these you can be sure it will kill you too but there will be no special hurry.” Earnest Hemingway, A Farewell To Arms.

  4. #4
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    CHECKSUM works with non-numeric data, so there is no need to recast as INT in your formula.

    Though I'm still not sure that is going to give him what he needs...
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

  5. #5
    Join Date
    Jul 2003
    Location
    San Antonio, TX
    Posts
    3,662
    Why are you doing this? To enforce data integrity upon INSERT/UPDATE? Or to support some business rule? Either way you're already using a database, so the answer should be in design, not checksum-based tricks.
    "The data in a record depends on the Key to the record, the Whole Key, and
    nothing but the Key, so help me Codd."

  6. #6
    Join Date
    Feb 2004
    Location
    San Antonio, TX
    Posts
    565
    hey trotsky!!
    calm down.

  7. #7
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    I'd love to hear the reason behind this... I can't for the life of me figure out why you might want/need to do it. I'm also with rdjabarov, and think that this smells very strongly of a high GQ (geek quotient) workaround for a case of poor relational design!

    -PatP

  8. #8
    Join Date
    Feb 2004
    Location
    San Antonio, TX
    Posts
    565
    that's twice that you have agreed with RDjabarov.
    hmmmmmmm is the feud over?


  9. #9
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    Feud? Did I miss a meeting?

    -PatP

  10. #10
    Join Date
    Feb 2004
    Location
    San Antonio, TX
    Posts
    565
    must have been the coma. when i first go here you guys would go at it like turtles and bunnies.

Posting Permissions

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