Avatar of fjkilken
fjkilken
 asked on

BINARY_CHECKSUM is not yielding expected value.

BINARY_CHECKSUM is not yielding expected value. 

I have 2 tables with 20 columns in each. 

16 of these columns have the same value and 4 do not, yet when I use BINARY_CHECKSUM it gives the same value.

Below is the data table.

Why are the checksum values not unique?

What alternative do I have to using BINARY_CHECKSUM ?

thanks!


SELECT BINARY_CHECKSUM(*) FROM #stg      --   -1571139392
SELECT BINARY_CHECKSUM(*) FROM #facts   --   -1571139392


 

source#facts#stg
dim_receipt_date_id-120210308
dim_dock_date_id-120210308
dim_min_dock_date_id-120210308
dim_max_dock_date_id-120210308
fact_idRMA3649121-1RMA3649121-1
order_nbrRMA3649121RMA3649121
line_nbr11
dim_order_date_id2021021720210217
dim_call_date_id2021021720210217
dim_disposition_date_id-1-1
dim_disposition_id33
dim_ship_date_id-1-1
dim_credit_date_id2021030820210308
dim_carrier_notify_date_id-1-1
dim_carrier_delivery_date_id-1-1
dim_carrier_collection_date_id-1-1
dim_carrier_expected_collection_date_id-1-1
dim_country_id2828
dim_site_id735735
dim_service_type_id4949
Microsoft SQL Server

Avatar of undefined
Last Comment
Scott Pletcher

8/22/2022 - Mon
fjkilken

ASKER
I found using HASHBYTES('SHA2_256', .. I will get a unique value but that will mean an update of a huge amount of rows in my tables and significant code change so I'd prefer not go that route if possible.
SELECT HASHBYTES
('SHA2_256',
      CAST( CONCAT(
      fact_id,
      order_nbr,
      line_nbr,
      dim_order_date_id,
      dim_call_date_id,
      dim_disposition_date_id,
      dim_disposition_id,
      dim_receipt_date_id,
      dim_dock_date_id,
      dim_ship_date_id,
      dim_credit_date_id,
      dim_carrier_notify_date_id,
      dim_carrier_delivery_date_id,
      dim_carrier_collection_date_id,
      dim_carrier_expected_collection_date_id,
      dim_min_dock_date_id,
      dim_max_dock_date_id,
      dim_country_id,
      dim_site_id,
      dim_service_type_id
      ) AS VARCHAR(MAX) )
) from #facts  


--Result>>
from #stg      --   0x95B73644AFA7D6E3DD91D3CB3774F0D828B102676A94818F6A718C0CA5CF82BD
from #facts      --   0x52B8DB837F549278305E7BC5FAC1E4BD6CF8822BFC70761403572A978299B1C0 
ASKER CERTIFIED SOLUTION
Scott Pletcher

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck