DECLARE @PortalID AS INT = PORTAL ID GOES HERE; /*Current PortalID to modify*/
DECLARE @WorkflowName AS nvarchar(40) = 'Workflow NAME GOES HERE'; /*Name of the workflow to apply to every page, get respective value from ContentWorkflows table*/
DECLARE @WorkflowPublishedStateName As nvarchar(40) = 'Workflow Published State Name GOES HERE'; /*Name of the last workflow state for when the content is published. get respective value from ContentWorkflowStates table*/

----------------- Do NOT EDIT Below this line ---------------------------------------
DECLARE @WorkflowID AS INT;
DECLARE @WorkflowPublishedState AS INT;
DECLARE @ContentTypeID AS INT;
DECLARE @ContentItemID AS INT;

SELECT @WorkflowID = WorkflowID FROM ContentWorkflows WHERE PortalID = @PortalID AND WorkflowName = @WorkflowName;
SELECT @WorkflowPublishedState = StateID FROM ContentWorkflowStates WHERE WorkflowID = @WorkflowID AND StateName = @WorkflowPublishedStateName
SELECT @ContentTypeID = ContentTypeID FROM ContentTypes WHERE ContentType = 'Tab';

DECLARE @ContentWorkflowPortal AS CURSOR;
SET @ContentWorkflowPortal = CURSOR FOR

/*Select all of the Tabs that have a workflow in the Portal*/
SELECT [ContentItemID]  
FROM ContentItems
WHERE StateID IN (SELECT StateID FROM ContentWorkflowStates WHERE WorkflowID IN (SELECT WorkflowID FROM ContentWorkflows WHERE PortalID = @PortalID)) AND ContentTypeID = @ContentTypeID;

OPEN @ContentWorkflowPortal;

FETCH NEXT FROM @ContentWorkflowPortal INTO @ContentItemID; 

  WHILE @@FETCH_STATUS = 0
    BEGIN 
		/*Set StateID to the new WorkflowID */
		UPDATE ContentItems SET StateID = @WorkflowPublishedState WHERE ContentItemID = @ContentItemID;

		FETCH NEXT FROM @ContentWorkflowPortal INTO @ContentItemID;
    END

CLOSE @ContentWorkflowPortal;
DEALLOCATE @ContentWorkflowPortal;

/*Set All the pending page drafts to Published */
UPDATE TabVersions SET IsPublished = 1 WHERE TabID IN (SELECT TabID FROM Tabs WHERE PortalID = @PortalID) AND IsPublished = 0;