concatenate EVERY 3rd CHARACTER using FUNCTION and PROCEDURE----------------
---------------------------USING PROCEDURE---------------------------------
CREATE PROC name_store(@stringname VARCHAR(300))
AS
BEGIN
DECLARE @char_concat varchar(50)=''
DECLARE @i int=3
WHILE(@i<LEN(@stringname))
BEGIN
select @char_concat=@char_concat+substring(@stringname,@i,1)
SET @i=@i+3
END
PRINT @char_concat
END
EXEC name_store 'JFSOAIRFGASLKEHLRUWAH...UDSFJGNZDSFH'
--------------------USING FUNCTION------------------------------------------------
ALTER FUNCTION get_concat_char(@FULLNAME VARCHAR(50))
RETURNS VARCHAR(MAX)
AS
BEGIN
DECLARE @I INT=3
DECLARE @NAME VARCHAR(100)=''
WHILE(@I<LEN(@FULLNAME))
BEGIN
SET @NAME=@NAME+SUBSTRING(@FULLNAME,@I,1)
SET @I=@I+3
END
RETURN @NAME;
END
SELECT DBO.get_concat_char('JZSDFJJBVSUDFSMAZBXFCVH')
---------------------------USING PROCEDURE---------------------------------
CREATE PROC name_store(@stringname VARCHAR(300))
AS
BEGIN
DECLARE @char_concat varchar(50)=''
DECLARE @i int=3
WHILE(@i<LEN(@stringname))
BEGIN
select @char_concat=@char_concat+substring(@stringname,@i,1)
SET @i=@i+3
END
PRINT @char_concat
END
EXEC name_store 'JFSOAIRFGASLKEHLRUWAH...UDSFJGNZDSFH'
--------------------USING FUNCTION------------------------------------------------
ALTER FUNCTION get_concat_char(@FULLNAME VARCHAR(50))
RETURNS VARCHAR(MAX)
AS
BEGIN
DECLARE @I INT=3
DECLARE @NAME VARCHAR(100)=''
WHILE(@I<LEN(@FULLNAME))
BEGIN
SET @NAME=@NAME+SUBSTRING(@FULLNAME,@I,1)
SET @I=@I+3
END
RETURN @NAME;
END
SELECT DBO.get_concat_char('JZSDFJJBVSUDFSMAZBXFCVH')