Is it possible to calculate the SQL Server sql_handle for a given SQL statement?
The 44-byte sql_handle has the following components (in order):

4 bytes: Byte-reversed integer code for the target cache e.g.

0x02000000 (2) for SQL Plans (CACHESTORE_SQLCP)
0x03000000 (3) for Object Plans (CACHESTORE_OBJCP)


4 bytes: Byte-reversed integer object id

For adhoc and prepared SQL this is an internal hash of the batch text as returned by @@PROCID or objectid in sys.dm_exec_plan_attributes.


16 bytes: MD5 hash of the batch text including (parameter definitions) prefix, if present.
20 bytes 0000000000000000000000000000000000000000