How to use SQL Server common functions (continuous update)

Source: Internet
Author: User
Tags how to use sql server how to use sql

Previously, I wanted to record some of the usual functions of SQL, but it has not been implemented ... Hey...

Until today, the substring () function is used, and in C # The starting value of this method is 0, and the starting value in SQL is 1. Silly points are not clear ...

This blog as a function of the use of SQL records, think of where to use where to write where ...

SubString (): the method used to intercept the specified string. The method has three parameters:

Parameter 1: Used to specify the string to manipulate.

Parameter 2: Used to specify the starting position of the string to intercept, with a starting value of 1.

Parameter 3: Used to specify the length to intercept.

Select substring (' abcdef ', 1,3)-    -Return to Abcselect substring (' 123456321 ', 0,2)-    -return 1, first place, best not to do so

Left (): returns the portion of the specified length in the given string. The method has two parameters:

Parameter 1: Used to specify the string to manipulate.

Parameter 2: Used to specify the length of the substring to be returned.

Select Left (' abc123 ', 3)        --Returns Abcselect to left (' right side portion ', 4)    --Returns

Right (): used to return the portion of the specified length in the given string. The method has two parameters:

Parameter 1: Used to specify the string to manipulate.

Parameter 2: Used to specify the length of the substring to be returned.

Select Right (' abc123 ', 3)        --Return 123select to right (' left side portion ', 4)-    -Return part

CharIndex (): used to return the starting position where the specified substring appears in the specified string. Returns 0 if it is not found. The method has two parameters:

Parameter 1: Used to specify the string to be searched.

Parameter 2: Used to specify a string to use as a retrieval.

Select CHARINDEX (' A ', ' 123a123 ')-        -Returns 4select charindex (' abc ', ' 123a123 ')-    -Returns 0select charindex (' abc ', ' 123abc123 ')    --Return 4

Stuff (): used to delete a specified length of character and insert a new character/value at the location of the deletion. The method has four parameters:

Parameter 1: Used to specify the string to manipulate.

Parameter 2: Used to specify the starting position of the character to be deleted.

Parameter 3: Used to specify the length of the character to be deleted.

Parameter 4: Used to specify the new string/value to insert at the location of the deletion.

Select Stuff (' 123abc456 ', 4,3, ' ABC ')-        -return 123abc456select stuff (' 123abc456 ', 1,3, ')-    -Return to abc456, replace with empty string

How to use SQL Server common functions (continuous update)

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.