declare @sample_data table ( A bigint , B varchar(100))
insert into @sample_data select 1234567890 ,'SAM'
insert into @sample_data select 2345678912 ,'HELLO'
insert into @sample_data select 7364557382 ,'MORNING'
select * from @sample_data
-- SQL
select
B
+ ' '
+ right(cast( A as varchar),6)
from
@sample_data
IF OBJECT_ID('tempdb..#table1') IS NOT NULL
DROP TABLE #table1;
CREATE TABLE #table1 (
A varchar(10) NOT NULL,
B varchar(30) NULL
);
INSERT INTO #table1 VALUES
('1234567890', 'SAM'),
('2345678912', 'HELLO'),
('7364557382', 'MORNING')
SELECT
A,
STUFF(A, 1, 5, LEFT(B + SPACE(5), 5)) AS New_A
FROM #table1