Git Product home page Git Product logo

davitalusefulsql's Introduction

Davital Useful SQL

A SQL Server Database project with some useful SQL CLR functions. Requires Visual Studio with SQL Server Data Tools (SSDT) installed.

Setup / Deployment

AdHoc/SqlClr.sql
Run on SQL Server instance to enable SQL CLR

UsefulSql.publish.xml
Publishes a database called UsefulSql to SQL Instance localhost

Functions

File system functions

dbo.GetFiles
Returns a list of all files in a directory (including all subfolders)

SELECT * FROM UsefulSql.dbo.GetFiles('c:\myfolder')

dbo.GetFileContents
Returns the contents of a file

SELECT UsefulSql.dbo.GetFileContents('c:\myfolder\myfile.txt')

Character encoding functions

dbo.GetUnicodeValues
Returns all characers from a string with their unicode integer values.

SELECT *
FROM 
	UsefulSql.dbo.GetUnicodeValues('some text')

dbo.ReplaceUnicodeValues
Returns a string with one character code replaced with another.

-- space = 32
-- underscore = 95
-- returns replace_spaces_with_underscores
SELECT UsefulSql.dbo.ReplaceUnicodeValues('replace spaces with underscores', 32, 95)	

Regex functions

The following regex related functions all have the following parameters

Param Description
value The string value to search
pattern The regular expression
regexOptions Regular expression options. Integer value that will be converted to System.Text.RegularExpressions.RegexOptions. Can be supplied as NULL, which will convert to RegexOptions.None

dbo.RegexGetMatches
Wrapper around Regex.Matches. Returns a row for each match.

SELECT * 
FROM 
	UsefulSql.dbo.RegexGetMatches('Extract individual words', '\b(\w+)\b', NULL)

dbo.RegexGetMatch
Wrapper around Regex.Match. Always returns a single row with the match result.

SELECT * 
FROM 
	UsefulSql.dbo.RegexGetMatch('Gets first match only', '\b(\w+)\b', NULL)

dbo.RegexIsMatch
Wrapper around Regex.IsMatch. Scalar function, returning a BIT indicating if the expression matches.

SELECT UsefulSql.dbo.RegexIsMatch('Returns 1 or 0', '\b(\w+)\b', NULL)

dbo.RegexGetGroups
Returns the values of groups defined in the regular expression.

SELECT * 
FROM 
	UsefulSql.dbo.RegexGetGroups('Dogs:20;Cats:10', '^Dogs\:?(?<Dogs>\d+);Cats\:?(?<Cats>\d+)$', NULL)
SELECT * 
FROM 
	UsefulSql.dbo.RegexGetMatch('Gets first match only', '\b(\w+)\b', NULL)

XML functions

dbo.GetXPathValue
Returns the first matching result of an XPath expression for the given XML.

SELECT UsefulSql.dbo.GetXPathValue('<root><item key="1" value="AAA" /></root>', '//root/item[@key="1"]/@value')

dbo.GetXPathValues
Returns all matching results of an XPath expression for the given XML.

SELECT *
FROM
	UsefulSql.dbo.GetXPathValues('<root><item key="1" value="AAA" /><item key="2" value="BBB" /></root>', '//root/item/@value')

davitalusefulsql's People

Contributors

daveb84 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.