harsha547
4/3/2017 - 9:32 PM

Retrieve the names which start and end with the same letter in SQL SERVER

Retrieve the names which start and end with the same letter in SQL SERVER


-- Q : Retrieve the names which starts and ends with the same letter ?

---- NAMES TABLE With ID and Name Fields

CREATE TABLE #Names
(
ID INT,
Name VARCHAR(30)
);

-- INSERT VALUES INTO THE #Name Table

INSERT INTO #Names VALUES(1,'Harsha');
INSERT INTO #Names VALUES(4,'Adora');
INSERT INTO #Names VALUES(2,'Rohan');
INSERT INTO #Names VALUES(5,'Earlene');
INSERT INTO #Names VALUES(3,'Neil');

--- RUN THE FOLLOWING QUERY


SELECT *
    FROM #Names
	WHERE LOWER(LEFT(Name,1)) = LOWER(RIGHT(Name,1));