How to get max Value Unit from field Value Unit based on first value before comma separated?

hi

i tried to do this .. Its a different way of doing it ..

if we get into performance tuning .. logical reads .. network round trips .. index seek and index scans and all that ..explain plan ..

then lot of stuff ...
Please let me know if this works for you !!

select   a.partid
       , valueunit 
from 
		finaltable a
			join 
        (select partid,max(cast(left(valueunit,patindex('%,%',valueunit)-1) as float)) as leftunit from finaltable group by partid) b 
            on 
	    left(a.valueunit,patindex('%,%',a.valueunit)-1) = b.leftunit 

image

1 Like