Skip to content

Instantly share code, notes, and snippets.

@kevinwucodes
Created October 23, 2018 21:19
Show Gist options
  • Select an option

  • Save kevinwucodes/62239ac1b7e2e3f87c6aa3c82cbfb5d3 to your computer and use it in GitHub Desktop.

Select an option

Save kevinwucodes/62239ac1b7e2e3f87c6aa3c82cbfb5d3 to your computer and use it in GitHub Desktop.
sql learning - hashing a row with specific columns in that row
;with names as (
select name, color
from (
values
('kevin','blue')
,('kevin','blue')
,('kevin','red')
) x (name, color)
)
select
n.name
,n.color
,xmlDoc = (select n.name, n.color from (values(null))foo(bar) for xml auto)
,hash = hashbytes('sha2_512', (select n.name, n.color from (values(null))foo(bar) for xml auto))
from names n
/*
name color xmlDoc hash
----- ----- -------------------------------- ----------------------------------------------------------------------------------------------------------------------------------
kevin blue <foo name="kevin" color="blue"/> 0x5302109C52D9D2A3B4A33165B123377CC5907DB8EF3713B4A1D4E1A114E3F3809BDCDE0409134F797B29BBD9A2F1521C7321761E4B1F1154FEEE1D4FD0991EC8
kevin blue <foo name="kevin" color="blue"/> 0x5302109C52D9D2A3B4A33165B123377CC5907DB8EF3713B4A1D4E1A114E3F3809BDCDE0409134F797B29BBD9A2F1521C7321761E4B1F1154FEEE1D4FD0991EC8
kevin red <foo name="kevin" color="red"/> 0xC69ADC5CE1765A2B092B53760FB8555A5511D6EBD40F19893D09E4AD54092FE49F3972706E204FEAC41BFED17529388EDFE15A4A5B1472E742605DBD7F785F79
(3 row(s) affected)
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment