A requirement once occurred at integration level at one of my client, We use below mentioned select clause combination with in-built sql functions "substr" and "instr" to achieve this task.
Segments separator was used there as "."
Segments separator was used there as "."
Example GLCode is as "Asset.OC.AFE.Element.Dept.Account.GLAC"
select gldebitacct
,substr(gldebitacct,1,instr(GLDEBITACCT,'.',1,1)-1) as Company
,substr(GLDEBITACCT,instr(GLDEBITACCT,'.',1,1)+1,instr(GLDEBITACCT,'.',1,2)-1-instr(GLDEBITACCT,'.',1,1)) as Asset
,substr(GLDEBITACCT,instr(GLDEBITACCT,'.',1,2)+1,instr(GLDEBITACCT,'.',1,3)-1-instr(GLDEBITACCT,'.',1,2)) as OC
,substr(GLDEBITACCT,instr(GLDEBITACCT,'.',1,3)+1,instr(GLDEBITACCT,'.',1,4)-1-instr(GLDEBITACCT,'.',1,3)) as AFE
,substr(GLDEBITACCT,instr(GLDEBITACCT,'.',1,4)+1,instr(GLDEBITACCT,'.',1,5)-1-instr(GLDEBITACCT,'.',1,4)) as ELEMENT
,substr(GLDEBITACCT,instr(GLDEBITACCT,'.',1,5)+1,instr(GLDEBITACCT,'.',1,6)-1-instr(GLDEBITACCT,'.',1,5)) as DEPT
,substr(GLDEBITACCT,instr(GLDEBITACCT,'.',1,6)+1,instr(GLDEBITACCT,'.',1,7)-1-instr(GLDEBITACCT,'.',1,6)) as ACCOUNT
,substr(GLDEBITACCT,instr(GLDEBITACCT,'.',1,7)+1,length(GLDEBITACCT)-instr(GLDEBITACCT,'.',1,7)) as ANALYSIS
from table-name
No comments:
Post a Comment