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