-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSetup1.sql
More file actions
56 lines (56 loc) · 1018 Bytes
/
Setup1.sql
File metadata and controls
56 lines (56 loc) · 1018 Bytes
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
45
46
47
48
49
50
51
52
53
54
55
56
IF DB_ID(N'ASsembler') IS NULL
CREATE DATABASE Assembler
GO
USE Assembler
DROP TABLE IF EXISTS Numbers
GO
CREATE TABLE dbo.Numbers
(
Num int primary key clustered
)
GO
INSERT dbo.Numbers
SELECT TOP (100000) ROW_NUMBER() OVER (ORDER BY @@SPID)
FROM sys.all_columns c1
CROSS JOIN sys.all_columns c2
GO
CREATE OR ALTER FUNCTION [dbo].[tfnChars]
(
@str nvarchar(200),
@Start int,
@Chars int
)
RETURNS TABLE AS
RETURN
SELECT TOP(@Chars) Num,
SUBSTRING(@Str, Num, 1) [Char],
ASCII(SUBSTRING(@Str, Num, 1)) [ASCII],
UNICODE(SUBSTRING(@Str, Num, 1)) [UNICODE]
FROM dbo.Numbers
WHERE Num >= @Start
AND Num < @Start + @Chars
ORDER BY Num ASC
GO
CREATE OR ALTER FUNCTION [dbo].[tfnReplaceNonAlpha]
(
@Str nvarchar(200),
@Start int,
@Chars int,
@Replace char(1)
)
RETURNS TABLE
AS
RETURN
SELECT
(
SELECT CASE
WHEN
(
(LOWER(C.Char) NOT BETWEEN 'a' AND 'z') AND
(C.Char NOT BETWEEN '0' AND '9')
) THEN @Replace
ELSE C.Char
END
FROM tfnChars(@Str, @Start, @Chars) C
FOR XML PATH ('')
) AS [Str]