How to Use the STUFF() Function in SQL Server: A Comprehensive Guide

Rumman Ansari   Software Engineer   2024-07-21 09:39:25   5809  Share
Subject Syllabus DetailsSubject Details
☰ TContent
☰Fullscreen

Table of Content:

STUFF() function inserts Replacement_expression, at the start position specified, along with removing the charactes specified using Length parameter.

Syntax:


STUFF(Original_Expression, Start, Length, Replacement_expression)

Code:


Select FirstName, LastName, STUFF(Email, 2, 3, '*****') as Email
From TableEmployee

STUFF() Function in SQL Server

prerequisite Code


CREATE TABLE TableEmployee(
FirstName varchar(50),
LastName varchar(50),
Email varchar(50)
)

INSERT INTO TableEmployee VALUES('Rambo', 'Azmi', 'Rambo@aaa.com')
INSERT INTO TableEmployee VALUES('Azam', 'Ali', 'Azam@aaa.com')
INSERT INTO TableEmployee VALUES('Inza', 'Hoque', 'Rambo@aaa.com')
INSERT INTO TableEmployee VALUES('Jaman', 'Sk', 'Jaman@aaa.com')
INSERT INTO TableEmployee VALUES('Samser', 'Alam', 'Samser@aaa.com')

SELECT * FROM TableEmployee



Stay Ahead of the Curve! Check out these trending topics and sharpen your skills.