A few basic questions related to Sql profile

(Sorry for the long-standing question, I'll try to be brief.)

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

One thing I ran into is some strange behavior that makes selective queries on the TextData field of a table generated by a traceback trace. It may have to do with the data type of the fields (ntext, null). I choose for certain values, but I get unexpected results. For example, if I do this:

select * from [TraceAnalyzer].dbo.TraceTable

      

and I am interested in such values:

exec [Sproc_of_interest] @parm1=992

      

I would make a request like this:

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

      

but the return result is empty.

Also, if I make a request like:

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

      

I am getting unexpected TextData values ​​like exec sp_reset_connection

Are the square brackets skewed in the criteria? I tried to skip them, but that just excludes everything. I don't know the escape characters in SQL fetch queries, but when I copy / paste a value from one of the offending records, the nested value contains nothing that matches the original query criteria.

Any ideas would be greatly appreciated. Thank.

+1


source to share


1 answer


[Sproc_of_interest]

in pattern syntax is interpreted as a match of one character that is in the set S,p,r,o,c,_,o,f,_,i,n,t,e,r,e,s,t

.

Below are three possible ways to address this issue.

1) Escape [

with square brackets

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

      



2) Use escape character

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

      

3) Use CHARINDEX

instead of hiding anything

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

      

0


source







All Articles