How does sys.dm_exec_sql_text work?

社会主义新天地 提交于 2019-12-13 13:45:36

问题


Can you please explain why

select * from sys.dm_exec_sql_text (sql_handle) throws an error (Invalid column name 'sql_handle'), but

select * from sys.sysprocesses cross apply sys.dm_exec_sql_text (sql_handle) is a valid query? Thank you.


回答1:


You need to join it to another table to get the sql_handle (or plan_handle).

For example:

select a.session_id, a.start_time, status, a.command, text from sys.dm_exec_requests a cross apply sys.dm_exec_sql_text(sql_handle).

sys.dm_exec_sql_text is a table valued function, it expects the parameter sql_handle or plan_handle to be passed to it in order to return a result as other functions do. The result returned is a table (rather than a scalar function which would return a single value).



来源:https://stackoverflow.com/questions/31968471/how-does-sys-dm-exec-sql-text-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!