监视器的过滤设置和动态跑SQL

In SQLServer Profiler:
TextData Not like [select TOP 20%]
this will better ApplicationName like NULL

This will dynamic run sql:
--This is the profiler shows
declare @p1 int
set @p1=426
exec sp_prepexec @p1 output,N'@P1 numeric(38,0),@P2 varchar(8000)',N'select IPROMO_THEME_ID, BELONGS_TO_HCARE, PROMO_THEME_CODE, PROMO_THEME_DESC, DEFUNCT from schema.table_name WITH (NOLOCK) where BELONGS_TO_HCARE = @P1 and PROMO_THEME_DESC = @P2 and defunct = ''N'' ',100,'hubin test for issue 942'
select @p1

--This is manually assembly sql
select IPROMO_THEME_ID, BELONGS_TO_HCARE, PROMO_THEME_CODE, PROMO_THEME_DESC, DEFUNCT
from schema.table_name WITH (NOLOCK) where BELONGS_TO_HCARE = 100
and PROMO_THEME_DESC = 'hubin test for issue 942' and defunct = 'N'

--This is dynamic run sql
DECLARE @IntVariable int;
DECLARE @StringVariable nvarchar(4000);
DECLARE @SQLString nvarchar(4000);
DECLARE @ParmDefinition nvarchar(4000);

/* Build the SQL string one time.*/
SET @SQLString =
N'select IPROMO_THEME_ID, BELONGS_TO_HCARE, PROMO_THEME_CODE, PROMO_THEME_DESC, DEFUNCT
from schema.table_name WITH (NOLOCK) where BELONGS_TO_HCARE = @P1
and PROMO_THEME_DESC = @P2 and defunct = ''N''';
SET @ParmDefinition = N'@P1 numeric(38,0),@P2 varchar(4000)';

/* Execute the string with the first paramter value.*/
SET @IntVariable = 100;
SET @StringVariable = 'hubin test for issue 942';
EXECUTE sp_executesql @SQLString , @ParmDefinition, @P1 = @IntVariable, @P2 = @StringVariable;

/* Execute the string with the second paramter value.*/
SET @IntVariable = 100;
SET @StringVariable = 'Moon Cake Festival';
EXECUTE sp_executesql @SQLString , @ParmDefinition, @P1 = @IntVariable, @P2 = @StringVariable;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值