snippetsqlMinor
How to convert a query hash to uint64?
Viewed 0 times
convertqueryuint64hashhow
Problem
How do I convert the query hash string "0x9F37D9B585242D49" to a uint64 needed by my extended event filter? Casting to bigint doesn't work as the value goes negative.
event
sql_statement_completed
filter
field : sqlserver.query_hash
operator : equal_uint64
value ???Solution
TSQL doesn't have unsigned 64bit integers, but .NET does.
outputs
And you also can filter on
outputs
var hash = 0x9F37D9B585242D49;
Console.WriteLine(hash);outputs
11472877949395676489And you also can filter on
query_hash_signed and provide a singed 64bit integer, which TSQL can produceselect cast(0x9F37D9B585242D49 as bigint)outputs
-6973866124313875127Code Snippets
var hash = 0x9F37D9B585242D49;
Console.WriteLine(hash);11472877949395676489select cast(0x9F37D9B585242D49 as bigint)-6973866124313875127Context
StackExchange Database Administrators Q#300477, answer score: 5
Revisions (0)
No revisions yet.