You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+23-17Lines changed: 23 additions & 17 deletions
Original file line number
Diff line number
Diff line change
@@ -1,23 +1,29 @@
1
1
# MySQLCLRFunctions
2
-
Free SQLCLR functions tested on SQL Server 2019
2
+
## Free SQLCLR functions tested on SQL Server 2019
3
3
4
-
Simple stuff to avoid spending $500 for a two year license (https://sqlsharp.com/full/)
5
-
It hasn't been updated in 2 years, so not very cool.
6
-
I use UNSAFE assemblies, because me likey.
7
-
Their names are a bit taxing. I call things StartsWith rather than SQL#.string_Is_A_BEGINNIN_WITH
8
-
Less parameters. These are annoying to have to fill out. Rather, do it the old fashion way: Make a new function!
9
-
CompareThese(a,b)
10
-
BestOf3(a,b,3)
11
-
Or make an agg.
12
-
Pass everything NVARCHAR(MAX) for now. Speed isn't the main problem. The main problem is that SQL Server functions are severely lacking.
4
+
These are simple functions I've written in order to avoid spending $500 for a two year license (https://sqlsharp.com/full/) of SQL#. For one, the product hasn't been updated in 2 years, and that's not very cool for a pay product.
13
5
14
-
If it's possible to think of a logical algorithm that can easily be described, then it's worth being a function.
6
+
FYI, warning, buyer beware on my stuff: I use UNSAFE assemblies, because half the reason to use SQLCLR is to get to functions that are not in SQL Server already, which is where the safe stuff is.
15
7
16
-
For instance, AnyOneOfTheseIsInThose, or something like that. If have a set. Are any of these items in this other list?
8
+
Another bug I have with SQL# is that their names are overly precious. They will name a function SQL#.string_Is_BEGINNING_WITH whereas I call it StartsWith, which is not coincidentally the same as the C# method. I try to align my names with C# when the functionality aligns. Less to remember.
17
9
18
-
To pass in lists, I just use delimited strings.
10
+
I also have less arguments on functions than SQL#. SQL Server does not support optional arguments on functions, and so these are annoying to have to fill out. Also, I forget what they are supposed to be, and I don't recall their documentation telling me if using DEFAULT will work.
11
+
Rather than every possible argument under the sun, I do it the old fashion way: I make a new function.
12
+
For example, hypothetically, I would do this:
13
+
> CompareThese(a,b)
14
+
> BestOf3(a,b,3)
15
+
> BestOf4(a,b,c,d)
16
+
> Or make an agg or a TVF.
19
17
20
-
Structure or class organization:
18
+
For reduced maintenance, I pass everything NVARCHAR(MAX). Speed is not my main problem. The main problem is that SQL Server functions are severely lacking and new functions are added every third decade. STRING_AGG is great, but a SQLCLR function can go back to at least 2012.
19
+
20
+
If it's possible to think of a logical algorithm that can easily be described and understood, and there's no confusion about what to expect in the output, then it's worth being a function.
21
+
22
+
For instance, I have a function called AnyOneOfTheseIsInThose, or something like that. It is for when I to know if there is a non-empty intersection of a list of values that I don't want to stuff into tables. It answers the simple question: Are any of these items in this other list?
23
+
24
+
To pass in lists, I use delimited strings, but I usually have an argument for the separating string. SPLIT_STRING from Microsoft, and most home-grown SQLCLR splitters seem to think all splitting is based on single characters. I support the string for the cases that come up.
25
+
26
+
## Structure or class organization, namespaces in other words:
21
27
<li>
22
28
Adaptors - Converts something to something else as an electronic power adaptor would. It's not a transformation, and it's reversible.
23
29
</li>
@@ -70,13 +76,13 @@ Structure or class organization:
70
76
<li>
71
77
StringTransform - Actual change being made, new information by structural abruption.
72
78
</li>
73
-
79
+
<br/>
74
80
My favorites have to be Matches, Ping, StartsWith, EndsWith, AnyOfTheseeAreAnyOfThose, HowMany, LeftOf, LeftOfNth, LeftOfNth, IndexOfLast
75
81
Also GetFirstName, Pieces, RTrimChar.
76
82
77
83
I have a bunch somewhere, and I need to add more.
78
84
79
-
Some ideas:
85
+
<h1>Some ideas:</h1>
80
86
- Better captures
81
87
- Escape for multi-level dynamic SQL generation
82
88
- A UNIX cut command for fixed-width
@@ -88,7 +94,7 @@ Some ideas:
88
94
- Some default formatters, like LogFileTimeStamp = "YYYYmmDDhh24missffffff" or some such. So I don't have to remember.
89
95
90
96
- Possibly push SQL work down? Like a TRUNCATE TABLE that pre-strips FKs, truncates, reloads, and tries to add the FKs back.
91
-
- Unix to/from for Active Directory columns
97
+
- Unix to/from for Active Directory columns.
92
98
- Natural language extraction of patterned speech.
0 commit comments