Skip to content
Advertisement

How to get only Capital letters from given value

I have a table it contains ID, Description and code columns. I need to fill code column using description column. Sample Description is “Investigations and Remedial Measures” so my code should be “IRM”.

Note: Is there any words like “and/for/to/in” avoid it

Advertisement

Answer

This code may help you..

 declare @input as varchar(1000) -- Choose the appropriate size
  declare @output as varchar(1000) -- Choose the appropriate size

 select @input = 'Investigations and Remedial Measures', @output = ''

 declare @i int

select @i = 0

while @i < len(@input)
begin
select @i = @i + 1

select @output = @output +  case when  unicode(substring(@input, @i, 1))between 65 
   and 90 then substring(@input, @i, 1)  else '' end

end

SELECT @output
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement