Svenson's  Bulletin Board Forum Index Svenson's Bulletin Board
Bulletin Board for boat building and model airplane building enthusiasts.
 
AlbumAlbum   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Recursive SQL split column data into rows

 
Post new topic   Reply to topic    Svenson's Bulletin Board Forum Index -> DB2
View previous topic :: View next topic  
Author Message
craig
Site Admin


Joined: 19 Feb 2006
Posts: 40

PostPosted: Tue Jun 15, 2010 6:25 am    Post subject: Recursive SQL split column data into rows Reply with quote

with t(ordinal,string,tbcreator,tbname,indexname) as
(
select 1,colnames,tbcreator,tbname,name as indexname from sysibm.sysindexes
union all
select ordinal+1
,case locate('+',string,2,octets)when 0 then null
else substr(string,locate('+',string,2,octets))
end as string
,tbcreator,tbname,indexname
from t
where string is not null
and ordinal < 100-- this line added to loose the 437 warning
),
tcols as
(
select ordinal
,case locate('+',string,2,octets)when 0 then
substr(string,2)
else
substr(string,2,locate('+',string,2,octets)-2)
end as column_name
,tbcreator,tbname,indexname
from t
where string is not null
),
sc as (
select tbcreator,tbname,rtrim(name) as name ,length
from sysibm.syscolumns
)
select sc.tbcreator
,sc.tbname
,si.indexname
,si.ordinal
,si.column_name as si_colname
,sc.length as sc_length
from tcols si,sc
where si.tbcreator=sc.tbcreator
and si.tbname=sc.tbname
and sc.name =si.column_name
order by sc.tbcreator
,sc.tbname
,si.indexname
,si.ordinal
;
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    Svenson's Bulletin Board Forum Index -> DB2 All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group