HiveBrain v1.2.0
Get Started
← Back to all entries
snippetsqlMinor

How to convert a query hash to uint64?

Submitted by: @import:stackexchange-dba··
0
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.

var hash = 0x9F37D9B585242D49;
Console.WriteLine(hash);


outputs

11472877949395676489


And you also can filter on query_hash_signed and provide a singed 64bit integer, which TSQL can produce

select cast(0x9F37D9B585242D49 as bigint)


outputs

-6973866124313875127

Code Snippets

var hash = 0x9F37D9B585242D49;
Console.WriteLine(hash);
11472877949395676489
select cast(0x9F37D9B585242D49 as bigint)
-6973866124313875127

Context

StackExchange Database Administrators Q#300477, answer score: 5

Revisions (0)

No revisions yet.