Created
July 25, 2017 11:17
-
-
Save smarenich/853cfe6fbe80222261ab60221fbd0596 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if exists(select * from sys.objects where object_id = object_id('dbo.pp_CopyDashboard') and objectproperty(object_id,'IsProcedure')=1) | |
drop proc dbo.pp_CopyDashboard | |
go | |
create procedure dbo.pp_CopyDashboard @companyID int, @dashboardID int AS | |
BEGIN | |
DECLARE @id int | |
DECLARE @ids table([id] int) | |
Insert Into Dashboard ([CompanyID], [Name], [DefaultOwnerRole], [ScreenID], [AllowCopy], [Workspace1Size], [Workspace2Size], [IsPortal], [CreatedByID], [CreatedByScreenID], [CreatedDateTime], [LastModifiedByID], [LastModifiedByScreenID], [LastModifiedDateTime]) | |
OUTPUT inserted.DashboardID INTO @ids | |
Select @companyID, [d].[Name] + '-Copy', [d].[DefaultOwnerRole], NULL, [d].[AllowCopy], [d].[Workspace1Size], [d].[Workspace2Size], [d].[IsPortal], [d].[CreatedByID], [d].[CreatedByScreenID], [d].[CreatedDateTime], [d].[LastModifiedByID], [d].[LastModifiedByScreenID], [d].[LastModifiedDateTime] | |
From Dashboard d | |
Where d.DashboardID = @dashboardID | |
Select top 1 @id = id from @ids | |
Insert Into Widget ([CompanyID], [DashboardID], [OwnerName], [Caption], [Column], [Row], [Workspace], [Width], [Height], [Type], [Settings], [CreatedByID], [CreatedByScreenID], [CreatedDateTime], [LastModifiedByID], [LastModifiedByScreenID], [LastModifiedDateTime], [NoteID]) | |
Select @companyID, @id, [w].[OwnerName], [w].[Caption], [w].[Column], [w].[Row], [w].[Workspace], [w].[Width], [w].[Height], [w].[Type], [w].[Settings], [w].[CreatedByID], [w].[CreatedByScreenID], [w].[CreatedDateTime], [w].[LastModifiedByID], [w].[LastModifiedByScreenID], [w].[LastModifiedDateTime], [w].[NoteID] | |
From Widget w | |
Where w.DashboardID = @dashboardID | |
END | |
Begin tran | |
exec pp_CopyDashboard 2, 33 | |
Rollback tran |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment