I have the following table:
create table #tbl
(
PartNumber varchar(20)
)
insert into #tbl values ('003A-I00-1')
insert into #tbl values ('003A-INT-1')
insert into #tbl values ('003A-I1')
insert into #tbl values ('003A-I2')
insert into #tbl values ('003A-I3')
I need to select the highest PartNumber where PartNumber is equal to 003A-I followed only by a number (or numbers). In other words, I need 003A-I3.
What I've tried:
select top 1 partnumber
from #tbl
where partnumber like '003A-I%' + '%[0-9]'
order by partnumber desc
But it doesn't work. It returns 003A-INT-1. I need 003A-I3.
I'm using MS SQL Server 2005.