본문 바로가기

DBMS/MSSQL

[MSSQL] STUFF

STUFF

문자열에 글자를 치환하고 싶은 경우 사용한다.

STUFF (string_expression, start, length, replacement_expression)
  • string_expression : 원본 문자열
  • start : 변경될 문자의 시작위치
  • length : 변경될 길이 수
  • replacement_expression : 새로운 문자열

# 1

SELECT STUFF('Hello, world!', 7, 5, 'there')
Hello, there!

# 2

SELECT STUFF('1234567890', 6, 0, '-')
12345-67890

# 3 

SELECT Name,
       STUFF(Name, CHARINDEX(' ', Name), LEN(Name), '') AS FirstName
FROM Employees
Name FirstName
John Smith John

 


There might be incorrect information or outdated content.

 

'DBMS > MSSQL' 카테고리의 다른 글

[MSSQL] STRING_AGG (GROUP_CONCAT)  (0) 2023.09.11
[MSSQL] CASE  (0) 2023.08.25
[MSSQL] DELETE  (0) 2023.08.04
[MSSQL] UPDATE  (0) 2023.08.04
[MSSQL] INSERT  (0) 2023.08.04