update tbl_STP_UserDashboards set shareConfig = 10 where ownerId = and ownerType = and dashboard = and fspro_userId = with dashboards as ( select fspro_userId, dashboard, ownerId, ownerType from tbl_STP_userDashboards where ownerId = and ownerType = and sourceDashboard = and sourceFspro_userId = ), widgetsToDelete as ( select w.* from tbl_STP_UserDashboardWidgets w inner join dashboards d on d.ownerId = w.ownerId and d.ownerType = w.ownerType and d.fspro_userId = w.fspro_userId and d.dashboard = w.dashboard ) delete w from tbl_STP_UserDashboardWidgets w where w.ownerId = and w.ownerType = and w.widgetId in ( select widgetId from widgetsToDelete ) delete from tbl_STP_UserDashboardSharing where ownerId = and ownerType = and dashboard = and fspro_userId = insert into tbl_STP_UserDashboardSharing ( ownerId, ownerType, fspro_userId, dashboard, linkType, linkId ) values ( , , , , , )