Process the statements traced by the SQL server

Everyone knows that SQL server is very powerful. Today I will share with you how to deal with the sentences traced by SQL server.

1. The following is the statement traced by SQL server:

exec sp_executesql N'
SELECT AntiName,YMResult,TestResult,c.Name
from [YmTpResult] a
left join DicYmyw b on a.AntiCode=b.Code
left join DicDurgClass c on b.ClassCode=c.Code
where YMNO =@ymno
',N'@ymno varchar(40)',

@ymno='20190528WSW_VITEK2011905280280000000486'

2. Process the traced statement as follows:

declare  @ymno varchar(40)
select @ymno='20190528WSW_VITEK2011905280280000000486'

SELECT AntiName,YMResult,TestResult,c.Name
from [YmTpResult] a
left join DicYmyw b on a.AntiCode=b.Code
left join DicDurgClass c on b.ClassCode=c.Code
where YMNO =@ymno

Note: The difference between the traced sentence and the processed sentence is the green mark.
Analysis: declare to make variables, select to assign values ​​to variables, if you are a developer, you can use the set statement.

You can refer to the following document:

3. View the traced statement information as follows:

Guess you like

Origin blog.csdn.net/h610443955/article/details/101761051