Home Forums Programming General Suggestion/solution for using Hashbytes across entire table RE: Suggestion/solution for using Hashbytes across entire table

  • As a solution for a single table (where the column list will never change), I can easily write a static expression to convert and concatenate the fields. I have already done that and tested that expression. BTW - to handle Null values, I use:

    declare @varbinnull varbinary(1) = convert(varbinary(1), '');

    ...

    + IsNull(Convert(varbinary(8000),<column_name>),@varbinnull)

    This allows concatenating all the fields with or without null values.

    For a single-table approach I can easily generate the concatenated list as:

    select '+ IsNull(Convert(varbinary(8000),[' + isc.Column_name + ']),@varbinnull)'

    from INFORMATION_SCHEMA.COLUMNS isc

    where isc.Table_Name = '<mytable>'

    order by isc.Ordinal_Position

    However, I am looking for a solution that doesn't need to be re-coded if a new column is added to the table (for one example).