Sample code is below:
DECLARE @reportExecutionId1 AS INT;
SET @reportExecutionId1 = 1;
SELECT 'DROP TABLE ' + '[' + TABLE_SCHEMA + '].[' + TABLE_NAME + ']'
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA LIKE '[ReptoolResult]%' AND TABLE_NAME LIKE 'ER' + CAST(@reportExecutionId1 AS VARCHAR) + '_%'
ORDER BY TABLE_SCHEMA, TABLE_NAME
Expected result set is below:
DROP TABLE [ReptoolResult].[ER1_1]
DROP TABLE [ReptoolResult].[ER1_2]
DROP TABLE [ReptoolResult].[ER1_3]
but the above sql should return below and don't want like below
DROP TABLE [ReptoolResult].[ER1_1]
DROP TABLE [ReptoolResult].[ER103_1]
DROP TABLE [ReptoolResult].[ER115_1]
DROP TABLE [ReptoolResult].[ER116_1]
DROP TABLE [ReptoolResult].[ER126_1]
DROP TABLE [ReptoolResult].[ER127_1]
DROP TABLE [ReptoolResult].[ER154_1]
Could you please suggest me any other way/solution.