Found this after some brain storming ...This will work if for ''53322'' as well as values like 53322
begin
declare @a as varchar(max) = 'and (GradutionYear =2016 and isnumeric(GradutionYear)=1 and GradutionYear<>0 ) and (Rank in(''53322'',53323,53324,53325,53327,53328,53329,53330,158676,158677,158678,158679)) and (GradutionYear =2016 and isnumeric(GradutionYear)=1 and GradutionYear<>0 )'
declare @b as varchar(max)
declare @c as varchar(max)
declare @d as varchar(max)
declare @e as varchar(max)
declare @f as varchar(max)
declare @g as varchar(max)
select @b = substring(@a, patindex('%(rank in(%',@a), len(@a))
select @c = substring(@b, 0, patindex('%)%',@b) + 2)
select @d = replace(replace(@c, '(rank in(',''), ')','')
select @d
select @e = isnull(@e,'') + ',''' + replace(val,'''','') + '''' from dbo.split(@d, ',')
select @f = stuff(@e,1,1,'')
select @g = replace(@c, @d, @f)
select @g = replace(@a, @c, @g)
select @g
end
Values of the variables as the code flows :-
@a and (GradutionYear =2016 and isnumeric(GradutionYear)=1 and GradutionYear<>0 ) and (Rank in(53322,53323,53324,53325,53327,53328,53329,53330,158676,158677,158678,158679)) and (GradutionYear =2016 and isnumeric(GradutionYear)=1 and GradutionYear<>0 )
@b (Rank in(53322,53323,53324,53325,53327,53328,53329,53330,158676,158677,158678,158679)) and (GradutionYear =2016 and isnumeric(GradutionYear)=1 and GradutionYear<>0 )
@c (Rank in(53322,53323,53324,53325,53327,53328,53329,53330,158676,158677,158678,158679))
(1 row(s) affected)
@d 53322,53323,53324,53325,53327,53328,53329,53330,158676,158677,158678,158679
@e ,'53322','53323','53324','53325','53327','53328','53329','53330','158676','158677','158678','158679'
@f '53322','53323','53324','53325','53327','53328','53329','53330','158676','158677','158678','158679'
@g (Rank in('53322','53323','53324','53325','53327','53328','53329','53330','158676','158677','158678','158679'))
@g and (GradutionYear =2016 and isnumeric(GradutionYear)=1 and GradutionYear<>0 ) and (Rank in('53322','53323','53324','53325','53327','53328','53329','53330','158676','158677','158678','158679')) and (GradutionYear =2016 and isnumeric(GradutionYear)=1 and GradutionYear<>0 )
@g is required expression
Thanks