title: Generate Delete Query using ONLY IN operator
body: <p>I am trying to write a query which generates the Delete query automatically based on the requirements. I will get To be deleted data from different tables and dump into temp table and then using this temp table I need to write query using IN operator, please suggest me, this is what I have tried.</p>
  <pre><code> SET NOCOUNT ON
      
      DECLARE @DeleteDisbursement TABLE (DisbursementId BIGINT, PolicyNumber NVARCHAR(10),DisbursementAmount DECIMAL(19,4))
      DECLARE @DeleteRecords Table(DisbursementId BIGINT,ActivityId BIGINT)
      INSERT INTO @DeleteDisbursement (DisbursementId,PolicyNumber,DisbursementAmount) 
      VALUES 
      (4576,'12345',3.00),
      (1232,'65455',143.44),
      (2341,'34234',228.95),
      (1111,'23155',414.89)
      
      SELECT * from @DeleteDisbursement
      
      DECLARE @GenerateScriptCount BIGINT =0
      DECLARE @DisbursementIDValue BIGINT =0
      DECLARE @ActivityIdValue BIGINT =0
      
      WHILE EXISTS(SELECT Top 1 1 FROM @DeleteDisbursement)
      BEGIN
         DECLARE @DisbursementId BIGINT =0
         DECLARE @PolicyNumber NVARCHAR(10)
         DECLARE @AccountId BIGINT =0
         DECLARE @ActivityId BIGINT
         DECLARE @DisbursementAmount DECIMAL(19,4)
      
      SELECT TOP 1 @DisbursementId =DisbursementId ,@PolicyNumber = PolicyNumber,@DisbursementAmount = DisbursementAmount
        FROM @DeleteDisbursement
      
      SET @ActivityId = (SELECT ActivityId FROM ActivityLog WHERE ActivityAmount = @DisbursementAmount)  
        
        IF (@ActivityId &gt; 0)
          BEGIN
            
           INSERT INTO @DeleteRecords (DisbursementId,ActivityId) VALUES(@DisbursementId,@ActivityId)
          
          END
        DELETE FROM @DeleteDisbursement WHERE DisbursementId = @DisbursementId
      
      END
          
          WHILE EXISTS(SELECT Top 1 1 FROM @DeleteRecords)
          BEGIN
      
              SELECT TOP 1 @DisbursementIDValue= @DisbursementId,@ActivityIdValue = @ActivityId FROM @DeleteRecords 
      
               PRINT 'DELETE FROM Disbursement Where DisbursementId IN (' + CONVERT(NVARCHAR(MAX), @DisbursementIDValue) +')' 
      
               PRINT 'DELETE FROM ActivityLog WHERE ActivityId IN (' + CONVERT(NVARCHAR(MAX), @ActivityIdValue) +')'  
      
              DELETE FROM @DeleteRecords WHERE DisbursementId = @DisbursementId
      
          END
      
      SET NOCOUNT OFF;
  </code></pre>
  <p>But its not working, Please help me How do I write query only 1 query which included in IN Operator like below :- Dynamically I want to PRINT this as I have showed in my query</p>
  <pre><code> DELETE FROM Disbursement Where DisbursementId IN (4576,1232,2341,1111)
      DELETE FROM ActivityLog WHERE ActivityId IN (1000,2000,3000,4000)
  </code></pre>