Use of SQL Server Functions left (), charindex (), and stuff ()

Source: Internet
Author: User

 

1. Left ()
Left (<character_expression>, <integer_expression>)
Returns character_expression, which starts from integer_expression at the left.

 

 
Select left ('abcdef', 3)
 
-- ABC

2. charindex ()
Charindex (<'substring _ expression' >,< expression>)

Returns the starting position of a specified substring in a string.

Here, substring _ expression is the character expression to be searched, and expression can be a string or a column name expression. If no substring is found, the return value is 0.
This function cannot be used for text and image data types.

 

 
Select charindex ('cd', 'abcdefg') -- 3 select charindex ('ac', 'abcdefg') -- 0

 

3. Stuff ()

 
Select stuff ('abcde', 2,3, 'mmmmmm ')
 
-- Ammme

 

-- Removes three characters starting from the second position (character B) from the first string (ABCDE,
-- Insert the second string at the start of the deletion, and create and return a string.

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.