@@ -34,13 +34,32 @@ Stay updated with latest changes
3434<a href =" https://twitter.com/zzzprojects " target =" _blank " ><img src =" http://www.zzzprojects.com/images/twitter_follow.png " alt =" Twitter Follow " height =" 24 " /></a >
3535<a href =" https://www.facebook.com/zzzprojects/ " target =" _blank " ><img src =" http://www.zzzprojects.com/images/facebook_like.png " alt =" Facebook Like " height =" 24 " /></a >
3636
37- ## Regular Expression - Split text with delimiters
37+ ## Evaluate dynamic arithmetic/math expression in SQL
38+ _ Make the impossible now possible. Evaluate C# expression in SQL to overcome limitations._
3839
39- ##### Problem
40- You need to split a text with delimiter and need a flexible and scalable solution which allow multiple delimiters and perform with millions rows.
40+ - Allow trusted users to create report field and filter
41+ - Consume Web Service
42+ - Replace text in template with String Interpolation
4143
42- ##### Solution
43- The Regex.Split function allow to use a regular expression to split a text which make it the most extensible solution.
44+ ``` csharp
45+ -- CREATE test
46+ DECLARE @table TABLE ( X INT , Y INT , Z INT )
47+ INSERT INTO @table VALUES ( 2 , 4 , 6 ), ( 3 , 5 , 7 ), ( 4 , 6 , 8 )
48+
49+ -- Result : 14 , 22 , 32
50+ DECLARE @sqlnet SQLNET = SQLNET :: New ('x*y+z' )
51+ SELECT @sqlnet .ValueInt ('x' , X )
52+ .ValueInt ('y' , Y )
53+ .ValueInt ('z' , Z )
54+ .EvalInt ()
55+ FROM @table
56+ ```
57+
58+ ## Split text with delimiter
59+ _Improve performance and capability for splitting text with an easy to use split function and LINQ expression_
60+ - Split text with multiple delimiters
61+ - Split text using a regular expression
62+ - Include row index
4463
4564```
4665-- CREATE test
@@ -57,46 +76,35 @@ FROM @t AS A
5776 ) AS B
5877```
5978
60- ##### Capability
61- Regex allow to resolve all case unsupported by “LIKE” and “PATHINDEX”. You can easily validate email or website url using regular expression.
79+ ## Use regular expression in SQL Server
80+ _Use Regex flexibility to overcome “LIKE ” and “PATHINDEX ” limitations ._
81+ - IsMatch
82+ - Match
83+ - Matches
84+ - Replace
85+ - Split
6286
63- ## Arithmetic Expression - Evaluate dynamic expression
87+ ```sql
88+ DECLARE @customer TABLE ( Email VARCHAR (255 ) )
6489
65- ##### Problem
66- You need a fast and flexible solution to support custom report fields and filters.
90+ INSERT INTO @customer
91+ 92+ ( 'invalid.com' ),
93+ 6794
68- ##### Solution
69- Evalute C# expression in SELECT statement and WHERE clause. The compiler honor operators precedence and parenthesis.
95+ DECLARE @valid_email SQLNET = SQLNET :: New ( 'Regex.IsMatch(email,
96+ @" ^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$ " ) ' )
7097
71- ``` csharp
72- -- CREATE test
73- DECLARE @table TABLE ( X INT , Y INT , Z INT )
74- INSERT INTO @table VALUES ( 2 , 4 , 6 ), ( 3 , 5 , 7 ), ( 4 , 6 , 8 )
75-
76- -- Result : 14 , 22 , 32
77- DECLARE @sqlnet SQLNET = SQLNET :: New ('x*y+z' )
78- SELECT @sqlnet .ValueInt ('x' , X )
79- .ValueInt ('y' , Y )
80- .ValueInt ('z' , Z )
81- .EvalInt ()
82- FROM @table
98+ -- SELECT 'invalid.com'
99+ SELECT * FROM @customer WHERE @valid_email .ValueString ('email' , Email ).EvalBit () = 0
83100```
84101
85- ##### Flexibility
86- Use C # language and features to build your expression
87- - C # Operators
88- - C # Keywords
89- - C # Objects
90- - Anonymous Type
91- - LINQ
92- - Etc .
93-
94- ## File Operation - Use FileInfo and DirectoryInfo
95- ##### Problem
96- You need to read / write files and need a readable , maintenable and secure solution without enabling xp_cmdshell .
97-
98- ##### Solution
99- Use well - known and documented C # object to read and write your files and improve your server security by impersonating the current user context .
102+ ## Replace xp_cmdshell with restrictive alternative
103+ _Avoid enabling xp_cmdshell and compromising your SQL Server and use instead a more restrictive solution ._
104+ - Impersonate Context
105+ - Improve maintainability
106+ - Improve readability
107+ - Improve security
100108
101109```csharp
102110-- REQUIRE EXTERNAL_ACCESS permission
@@ -113,11 +121,6 @@ return dir.GetFiles("*.*")
113121EXEC dbo .SQLNET_EvalResultSet @sqlnet
114122```
115123
116- ##### Security
117- Stop compromising your SQL Server with ** HIGH security risk ** procedure like xp_cmdshell which has no restriction and can execute bat / cmd script .
118-
119- Use a ** more restrictive ** solution with Eval SQL .NET and [EXTERNAL_ACCESS ](https :// msdn.microsoft.com/library/ms345101.aspx) permission which limit what the user can do.
120-
121124## FREE vs PRO
122125
123126Features | FREE Version | ** [PRO Version ](http :// eval-sql.net/#pro)**
0 commit comments