Paste this into a new question or an answer at dba.stackexchange.com:
<!-- --> > create table SampleData > ( > Id int not null > , Name nvarchar(32) > ) > > insert SampleData (Id, Name) > values (1, 'Select') > , (2, 'Emp_id') > , (3, ',') > , (4, 'Emp_Name') > , (5, 'AS') > , (6, 'EmployeeName') > , (7, ',') > , (8, 'Dept_Name') > , (9, 'AS') > , (10, 'DepartmentName') > , (11, 'CASE') > , (12, 'WHEN') > , (13, 'Emp_Status=''Y''') > , (14, 'THEN') > , (15, '1') > , (16, 'ELSE') > , (17, '0') > , (18, 'END') > , (19, 'AS') > , (10, 'EmployeeStatus') > , (11, 'From') > , (12, 'Employee') > > select b.Id, a.Name + ' ' + b.Name + ' ' + c.Name StrName > from SampleData b > inner join SampleData a on a.Id = b.id - 1 > inner join SampleData c on c.Id = b.id + 1 > where b.Name = 'AS' > > > > > > GO > > <pre> > Id | StrName > -: | :-------------------------- > 5 | Emp_Name AS EmployeeName > 9 | Dept_Name AS DepartmentName > 9 | Dept_Name AS EmployeeStatus > </pre> *db<>fiddle [here](https://dbfiddle.uk/?rdbms=sqlserver_2017&fiddle=b2c5dc069e4355eeb0327b732a7a52c7)*
back to fiddle