Skip to Content
0
Former Member
Mar 17, 2011 at 06:26 AM

Autocode Generate

22 Views

hi,

i am using following query for auto code generation group wise

declare @temp as char(20) 
IF $[OITM.ItmsGrpCod] = 101 
BEGIN 
set @temp=(select isnull(max(right(ItemCode,6)),0) + 1 from OITM where (ItmsGrpCod= 101) and (len(ItemCode)=7)) 
set @temp='FAB'+isnull(replicate(0,6-len(@temp)),'')+@temp 
select cast(@temp as char(20)) 
END
ELSE IF $[OITM.ItmsGrpCod] = 104 
BEGIN 
set @temp=(select isnull(max(right(ItemCode,6)),0) + 1 from OITM where (ItmsGrpCod= 104) and (len(ItemCode)=7)) 
set @temp='BRD'+isnull(replicate(0,6-len(@temp)),'')+@temp 
select cast(@temp as char(20)) 
END

but this does not increment code automatically every time it shows me FAB000001 and BRD000001

thanks

rahul