SQL Server uses the PARSENAME function to handle IP address strings

Source: Internet
Author: User

The IP V4 address is a 3-point delimited string that sometimes needs to be processed in the database, such as determining if the IP address is valid.

The usual way to think of it is to write a function, such as using CHARINDEX, substring and other function combinations to obtain the various parts of the IP address, and then processing.

When SQL Server is used to represent objects, it usually takes

The name of the schema , the name of the database , the name of the schema, the name of the object, the name of the linked server, database name. Schema name. Object name , etc.

such as Dbo.tablename, Master.dbo.tablename, [192.168.1.100].master.dbo.tablename

The purpose of the ParseName function is to get the specified portion of the SQL Server object, such as the database name part to get Master.dbo.tablename

Just use Select ParseName (' Master.dbo.tablename ', 3) and the result is master.

Fortunately, the format of the IP V4 is just like [192.168.1.100].master.dbo.tablename this representation,

So we use ParseName (' 192.168.1. 1) Get 100,parsename (' 192.168. 1. 100 ', 2) Get 1,parsename (' 192. 168. 1.100 ', 3) Get 168,parsename ('192. 168.1.100 ', 4) can get 192.

After getting the various parts of the IP address, it is much more convenient to process it.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.