A couple of basic Sql Profiler questions

删除回忆录丶 提交于 2019-12-24 04:11:53

问题


(Sorry for the longish question, I'll try to be concise.)

I'm running SQL Server Profiler and I'm chasing down some performance issues. I'm relatively new to what the profiler does and I've exported the traces into a table so I can run queries against the data.

One thing I've been running up against is some seemingly odd behavior doing select queries against the TextData field of the table generated by the trace export. It may have to do with the field's data type (ntext, null). I'm selecting for particular values, but getting unexpected results. For example, if I do this:

select * from [TraceAnalyzer].dbo.TraceTable

and I'm interested in values like this:

exec [Sproc_of_interest] @parm1=992

I'd do a query like this:

select * from [TraceAnalyzer].dbo.TraceTable
where TextData like '%exec [Sproc_of_interest] @parm1=%'

but the return result is empty.

Also, if I do a query like:

select * from [TraceAnalyzer].dbo.TraceTable
where TextData like '%exec [Sproc_of_interest]%'

I get unexpected TextData values like exec sp_reset_connection

Would the square brackets in the criteria be messing things up? I've tried omitting them, but that just excludes everything. I'm not aware of escape characters in SQL select queries, but when I copy/paste the value from one of the offending records, the pasted value does not appear to contain anything that would meet the original query's criteria.

Any insights would be greatly appreciated. Thanks.


回答1:


[Sproc_of_interest] in the pattern syntax is interpreted as matching one character that is in the set S,p,r,o,c,_,o,f,_,i,n,t,e,r,e,s,t.

Three possible ways of solving this are below.

1) Escape [ with square brackets

LIKE '%exec [[]Sproc_of_interest] @parm1=%'

2) Use an escape character

LIKE 'exec \[Sproc_of_interest] @parm1=' ESCAPE '\'

3) Use CHARINDEX instead of escaping anything

WHERE CHARINDEX('exec [Sproc_of_interest] @parm1=' , TextData) > 0


来源:https://stackoverflow.com/questions/13198870/a-couple-of-basic-sql-profiler-questions

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