Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtemplate.sql
More file actions
Latest commit
44 lines (37 loc) · 1.42 KB
/
Copy pathtemplate.sql
File metadata and controls
44 lines (37 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
* Customer-facing SQL script template
*
* NOTE: This script defaults to rolling back changes.
* To commit changes, set @saveChanges = 1.
*/
declare @saveChanges bit; --set @saveChanges = 1
declare @supportedVersions varchar(1000); select @supportedVersions='10.2.*, 10.3.*, 11.*'
-- Ensure the correct database version
BEGIN
declare @sep char(2); select @sep=', '
ifnotexists(select*
fromdbo.SystemConfig
join (
selectSUBSTRING(@supportedVersions, C.Value+1, CHARINDEX(@sep, @supportedVersions+@sep, C.Value+1)-C.Value-1) asValue
fromdbo.Counter C
whereC.Value< DataLength(@supportedVersions) andSUBSTRING(@sep+@supportedVersions, C.Value+1, DataLength(@sep)) = @sep
) VersiononSystemConfig.ValuelikeREPLACE(Version.Value, '*', '%') andSystemConfig.Name='Version'
) begin
raiserror('Only supported on version(s) %s',16,1, @supportedVersions)
goto DONE
end
END
declare @error int, @rowcount int
setnocounton; begintran; savetran TX
/*
script code goes here
*/
/* after every modifying statement, check for errors; optionally, emit status */
select @rowcount=@@ROWCOUNT, @error=@@ERROR
if @error<>0goto ERR
raiserror('%d foobars blah-blahed', 0, 1, @rowcount) withnowait
if (@saveChanges =1) beginraiserror('Committing changes', 0, 254); goto OK end
raiserror('To commit changes, set @saveChanges=1',16,254)
ERR: raiserror('Rolling back changes', 0, 255); rollbacktran TX
OK: commit
DONE: