Use of the SQL Server function left (), charindex (), Stuff ()

Source: Internet
Author: User
Tags first string

1. Left ()
Left (<CHARACTER_EXPRESSION>, <integer_expression>)
Returns the integer_expression character from the left of character_expression.

[SQL]View PlainCopy
    1. Select Left (' abcdef ', 3)
[SQL]View PlainCopy
    1. --abc

2.charindex ()
CHARINDEX (< ' substring_expression ';, <expression>)

Returns the beginning of the occurrence of a specified substring in a string.

Where substring _expression is the character expression to look for, expression can be a string or a column name. If no substring is found, a value of 0 is returned.
This function cannot be used with text and image data types.

[SQL]View PlainCopy
    1. Select CHARINDEX (' CD ',' ABCDEFG ') --3
    2. Select CHARINDEX (' ac ',' ABCDEFG ') --0


3.stuff ()

[SQL]View PlainCopy
    1. Select Stuff (' abcde ', 2,3,' mmmm ')
[SQL]View PlainCopy
    1. --Ammme


--by removing the three characters from the second position (character B) in the first string (ABCDE),
--then insert the second string at the beginning of the deletion, creating and returning a string.

Use of the SQL Server function left (), charindex (), Stuff ()

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.