Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 MAX with SUBSTRING

Author  Topic 

er.bhupinder53
Starting Member

13 Posts

Posted - 2011-07-07 : 21:11:51
I have a column where I have to split a value starting with P
and want to find the maximum number out of the result.
Example I have data like:

Paa00001,Pab00002,paa00005,pqa00012
I want result as "00012" the maximum integral value. and then add one to it with a constant prefix PXX
So in this case final expected result would be : "PXX00013"

I have used the following code and getting nothing:

SELECT MAX(SUBSTRING (id, 4,9) as interger ) as Maxvalue
FROM my_table
WHERE id like 'P%'

Please help
   

- Advertisement -