Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7dfc33e

Browse files
authored
Update Update_Subscription_Owner.sql
1 parent d399b14 commit 7dfc33e

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

‎Miscellaneous/Scripts/SQL/Update_Subscription_Owner.sql

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,44 +15,44 @@ GO
1515
:SETVAR OldUser "DOMAIN\OldUserName"
1616
:SETVAR NewUser "DOMAIN\NewUserName"
1717

18-
SET XACT_ABORT ON
19-
BEGIN TRANSACTION
18+
SET XACT_ABORT ON;
19+
BEGIN TRANSACTION;
2020

21-
PRINT '====================================================================='
22-
PRINT 'Update subscriptions...'
21+
PRINT '=====================================================================';
22+
PRINT 'Update subscriptions...';
2323
PRINT '====================================================================='
2424

25-
;WITH
26-
new_owner
25+
WITH
26+
[new_owner]
2727
AS
2828
(
29-
SELECT UserID, UserName FROM dbo.Users WHERE UserName = N'$(NewUser)'
29+
SELECT [UserID], [UserName] FROM [dbo].[Users] WHERE [UserName] = N'$(NewUser)'
3030
)
3131
,
32-
subscription_source
32+
[subscription_source]
3333
AS
3434
(
3535
SELECT DISTINCT
36-
s.[Report_OID]
37-
, [OldOwner] = ou.[UserName]
38-
, [OldOwnerID] = ou.[UserID]
39-
, [NewOwner] = nu.[UserName]
40-
, [NewOwnerID] = nu.[UserID]
36+
[s].[Report_OID]
37+
, [OldOwner] = [ou].[UserName]
38+
, [OldOwnerID] = [ou].[UserID]
39+
, [NewOwner] = [nu].[UserName]
40+
, [NewOwnerID] = [nu].[UserID]
4141
FROM
42-
[dbo].[Subscriptions] AS s
43-
INNER JOIN [dbo].[Users] AS ou ON ou.[UserID] = s.[OwnerID]
44-
, new_owner AS nu
42+
[dbo].[Subscriptions] AS [s]
43+
INNER JOIN [dbo].[Users] AS [ou] ON [ou].[UserID] = [s].[OwnerID]
44+
, [new_owner] AS [nu]
4545
WHERE
4646
1=1
47-
AND ou.[UserName] = N'$(OldUser)'
47+
AND [ou].[UserName] = N'$(OldUser)'
4848
)
4949
--SELECT * FROM subscription_source
50-
MERGE [dbo].[Subscriptions] AS T
51-
USING subscription_source AS S ON T.[Report_OID] = S.[Report_OID]
50+
MERGE [dbo].[Subscriptions] AS [T]
51+
USING [subscription_source] AS [S] ON [T].[Report_OID] = [S].[Report_OID]
5252
WHEN MATCHED
5353
THEN UPDATE SET
54-
T.[OwnerID] = S.[NewOwnerID]
55-
OUTPUT @@ServerName AS ServerName, db_name() AS DatabaseName, $action, inserted.*, deleted.*;
54+
[T].[OwnerID] = [S].[NewOwnerID]
55+
OUTPUT @@ServerName AS [ServerName], DB_NAME() AS [DatabaseName], $action, [inserted].*, [deleted].*;
5656

5757

5858
PRINT '******* ROLLBACK TRANSACTION ******* ';
@@ -61,6 +61,6 @@ ROLLBACK TRANSACTION;
6161
--PRINT '******* COMMIT TRANSACTION ******* ';
6262
--COMMIT TRANSACTION;
6363

64-
PRINT '====================================================================='
65-
PRINT 'Finished...'
66-
PRINT '====================================================================='
64+
PRINT '=====================================================================';
65+
PRINT 'Finished...';
66+
PRINT '=====================================================================';

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /