sys.dm_exec_sql_text.dbid is not always populated
Books Online says about this column.
"ID of database.
For ad hoc and prepared SQL statements, the ID of the database where the statements were compiled."
However, it seems that dbid is NULL when the text is not from a stored procedure. This bug should be fixed, as the current state makes it very difficult to answer questions like "which are the 5 most expensive queries in this database".
Surely, it is not the documentation that is wrong, is it?
Upvotes: 2<=-=Mar 14 2017 8:16AM=-=>
It looks like a bug, we are investigating this.