Quantcast
Viewing all articles
Browse latest Browse all 41

T-SQL template parser

Just for the heck of it, I scratched together a template parser for T-SQL Image may be NSFW.
Clik here to view.
GitHub
. The usage of this function is similar to the STRING_SPLIT() function, except instead of splitting a string by a delimiter character, we want to split a string according to a defined template.

SELECT *
FROM dbo.Template_Split(
    'Wingtip Toys (Bethel Acres, OK)',
    '% (%, %)'
);

… will generate the following output:

Image may be NSFW.
Clik here to view.

Notice how the “%” wildcard character denotes how the string is split. Unlike the fancy stuff you can do with regular expressions, T-SQL wildcards don’t allow you to define capture groups, so this function is unfortunately constrained to just using “%”. I hope it will still come in handy to someone out there.

That’s it, that’s the post. Enjoy!


Viewing all articles
Browse latest Browse all 41

Trending Articles