I have a query I am using to return values:
DECLARE @ VALUE varchar(1000) = 'ACELLA PHARMA [A200]'
select
a.item_id,
attr_vals = concat(a.attr_val, ' ', quotename(b.attr_val))
from
ndc_attr as a
left outer join
[NDC_ATTR] b
on b.field_id = 144
and a.field_id = 225
where
b.attr_val is not null
and b.attr_val like '%' +@ VALUE + '%'
The thing is I need the value within the parenthesis: A200 in this example.
I have tried to break up the query by adding an if statement in it:
if @VALUE like '%[%' and @VALUE like '%]%'
begin
SET @VALUE = SUBSTRING(@VALUE, CHARINDEX('[', @VALUE) + 1, LEN(@VALUE) - 1)
end
But oddly, the full string is returning ('ACELLA PHARMA [A200]').
How can I break up this value so only the string within the brackets is on @VALUE?