Development resources, articles, tutorials, code samples, tools and downloads for ASP.Net, SQL Server, Reporting Services, T-SQL, Windows, AWS, SAP HANA and ABAP
Sometimes programmers need to parse for domain name from a string expression which identifies the URL of a web address.
I tried to create SQL Server user-defined function which parses input url string parameter for the domain name.
On SQL Server developer can use this SQL function by running the Create Function script given below and try how the function works on different situations by running the sample select query to see the results.
I used a SQL variable data type nvarchar for keeping the url address since localized address names will probably be used on some places with an increasing atitude.
The first step in the user defined function is defining the url address string is in HTTP protocol or HTTPS protocol.
Then the sql statements controls the url address variable for "/", and "." characters and parses the url address string to fetch the domain name.
Here is the source codes of SQL function used to parse domain name from given URL address string parameter.
Here is the sample SQL Select query which SQL programmers can use to test the SQL Server user defined function Parse_For_Domain_Name which is created to parse url address to fetch the domain name.
Output will be as seen below
Developers can realize that different valid forms of URL addresses are considered and domain name is fetched among those different formats.