Hashbyte in persisted computed column?

  • Hi,

    I'm trying to create a persisted computed column using the hashbyte function. But when adding this column to my table I get a error message which says:

    Computed column 'check' in table 'tbl_cons' cannot be persisted because the column is non-deterministic.

    My Alter Statement looks like this: Alter TAble tbl_cons Add [check] AS (hashbytes('md5', isnull ([TICKER] ,'') + isnull ( convert(nvarchar, CPN) ,'') + ... )

    It builds a hash out of ca. 200 columns. AFAIK hashbytes is non-deterministic for NULL values, but as I'm using isnull() this can never happen.

    Before hashbytes I used checksum, but there have been changes on the underlying columns which didn't change the checksum.

    Any chance to make this column persisting?

    Regards,

    Jan

  • Something else is making it non-deterministic. I just tried using hashbytes of a single column in a persisted computed column, and it does work. Check for any other calls that might make it non-deterministic.

    ----------------------------------------------------------------------------------
    Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?

  • Hi Matt,

    thanks for that hint, it seems that I'm getting this error if one of the used columns is datetime, although it is converted into nvarchar.

    I'll try to find an workaround and post it.

    Regards,

    Jan

  • Keep in mind that getdate() is non-deterministic, so that if it happens to be using that your result will forever be non-deterministic.

    ----------------------------------------------------------------------------------
    Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?

  • Hi,

    it seems that this error only occurs by converting datetime columns into a style which contains spaces. Using 126 as style (also tried 101 - 105) works fine, while using 106 produces this error message.

    Update: This works, but it isn't possible to replicate this column because sql server says it is non-deterministic. I think this is a bug on SQL Server 2005, what do you guys think?

    Regards,

    Jan

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply