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;
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;