Where conidition to dyanmic SQL

Hi all,

I am struggling to add this Where clause to the below dynamic SQL: - can someone help me with the syntax please

status IN (SELECT Value FROM dw.sg_SplitMultiValuedString_TF (@Status, ',') as StatusCodeString)

DECLARE @BaseTable NVARCHAR(255)

SET @BaseTable = @GroupBy


DECLARE @DynamicSQL NVARCHAR(max)

SET @DynamicSQL =N'SELECT *

   FROM dw.tb p1
   WHERE
                  do between @StartTime and @EndTime +1
                 AND ls <> 4
                 AND @BaseTable  = @BaseTable
                 AND Oi in (select OrgId from dw.RS_OrgExpansion_TF('
                 + Quotename(@OrgId, '''')
                 +
                 ''+'))'

exec sp_executeSQL @DynamicSQL,
N'@StartTime datetime, @EndTime datetime, @BaseTable Nvarchar(255)',
@StartTime, @EndTime, @BaseTable

 

May 21st, 2015 8:07pm

DECLARE @BaseTable NVARCHAR(255)
SET @BaseTable = @GroupBy

DECLARE @DynamicSQL NVARCHAR(max)
SET @DynamicSQL =N'SELECT *

   FROM dw.tb p1 
   WHERE 
                  do between @StartTime and @EndTime +1
                 AND ls <> 4
				 AND status IN (SELECT Value FROM dw.sg_SplitMultiValuedString_TF (@Status, '','') as StatusCodeString)
                 AND @BaseTable  = @BaseTable 
                 AND Oi in (select OrgId from dw.RS_OrgExpansion_TF(' 
                 + Quotename(Orgid, '''') 
                 +
                 ''+'))'

exec sp_executeSQL @DynamicSQL,
N'@StartTime datetime, @EndTime datetime,@BaseTable Nvarchar(255),@status nvarchar(255)',
@StartTime, @EndTime, @BaseTable,@status


Free Windows Admin Tool Kit Click here and download it now
May 21st, 2015 8:23pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics