if you don't have starting values in a numbering column already, how do you get the sequences started?
Main Topics
Browse All TopicsI need to populate the Numbering column based on two other columns pattern. If my node level =2 and appears the second time then number = 1200. Difficult to explain, please see the follwing data.
Node_Level Tree_seq Numbering
1 1 1000
2 2 1100
3 3 1110
4 4 1111
2 5 1200
3 6 1210
2 7 1300
3 8 1310
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Node_leve 1 default to 1000.
Then the first time node_level =2 the value will be 1100...
Then the first time node_level =3 the value will be 1X10 X is the numbering for previous node_level =2.
Then the first time node_level =4 the value will be 1XY1 X is the numbering for previous node_level =2.
Thanks.
Try this:
Select
(Select cast(count(*) as char(1)) from YOURTABLE T2
where T2.Tree_Seq <= T1.Tree_Seq
and T2.node_level = T1.node_level
and T1.node_level = 1)
||
(Select cast(count(*) as char(1)) from YOURTABLE T2
where T2.Tree_Seq <= T1.Tree_Seq
and T2.node_level = T1.node_level
and T1.node_level = 2)
(Select cast(count(*) as char(1)) from YOURTABLE T2
where T2.Tree_Seq <= T1.Tree_Seq
and T2.node_level = T1.node_level
and T1.node_level = 3)
||
(Select cast(count(*) as char(1)) from YOURTABLE T2
where T2.Tree_Seq <= T1.Tree_Seq
and T2.node_level = T1.node_level
and T1.node_level = 4)
From YOURTABLE T1
Try again:
Select
(Select cast(count(*) as char(1)) from YOURTABLE T2
where T2.Tree_Seq <= T1.Tree_Seq
and T2.node_level = T1.node_level
and T1.node_level = 1)
||
(Select cast(count(*) as char(1)) from YOURTABLE T2
where T2.Tree_Seq <= T1.Tree_Seq
and T2.node_level = T1.node_level
and T1.node_level = 2)
||
(Select cast(count(*) as char(1)) from YOURTABLE T2
where T2.Tree_Seq <= T1.Tree_Seq
and T2.node_level = T1.node_level
and T1.node_level = 3)
||
(Select cast(count(*) as char(1)) from YOURTABLE T2
where T2.Tree_Seq <= T1.Tree_Seq
and T2.node_level = T1.node_level
and T1.node_level = 4)
From YOURTABLE T1
dqmq: That is not the pattern. if node_level =3 then the pattern will be 1XX0.
SET DEFINE OFF;
Insert into T
(NODE_LEVEL, TREE_SEQ)
Values
(4, 4);
Insert into T
(NODE_LEVEL, TREE_SEQ)
Values
(2, 5);
Insert into T
(NODE_LEVEL, TREE_SEQ)
Values
(3, 6);
Insert into T
(NODE_LEVEL, TREE_SEQ)
Values
(1, 1);
Insert into T
(NODE_LEVEL, TREE_SEQ)
Values
(2, 2);
Insert into T
(NODE_LEVEL, TREE_SEQ)
Values
(3, 3);
COMMIT;
sdstuber: Here is data. Node_level =4 tree_seq should be 1311 but your result is 1211.
SET DEFINE OFF;
Insert into T
(NODE_LEVEL, TREE_SEQ)
Values
(4, 4);
Insert into T
(NODE_LEVEL, TREE_SEQ)
Values
(2, 5);
Insert into T
(NODE_LEVEL, TREE_SEQ)
Values
(3, 6);
Insert into T
(NODE_LEVEL, TREE_SEQ)
Values
(2, 7);
Insert into T
(NODE_LEVEL, TREE_SEQ)
Values
(3, 8);
Insert into T
(NODE_LEVEL, TREE_SEQ)
Values
(4, 9);
Insert into T
(NODE_LEVEL, TREE_SEQ)
Values
(1, 1);
Insert into T
(NODE_LEVEL, TREE_SEQ)
Values
(2, 2);
Insert into T
(NODE_LEVEL, TREE_SEQ)
Values
(3, 3);
COMMIT;
I'm with sdstuber. I don't understand.
I still don't see where tab_seq comes into play.
I thought it was node occurrence = number offset. Where nodes occurence=numbers ABCD
so
node 1 = 1000
node 2 = 0100
node 3 = 0010
node 4 = 0001
adn every node occurrence increments the offeset so second node 3 would be 0020.
Please set us straight.
Business Accounts
Answer for Membership
by: sdstuberPosted on 2009-11-06 at 12:43:46ID: 25762867
you need starting values for each numbering for the first occurence of a node_level.
I assume you already have those in your numbering column and you just need to populate the 2nd and subsequent occurences of each node_level
SELECT node_level,
tree_seq,
CASE WHEN rn = 0 THEN numbering ELSE first_numbering + (100 * rn) END numbering
FROM (SELECT node_level,
tree_seq,
numbering,
ROW_NUMBER() OVER (PARTITION BY node_level ORDER BY tree_seq) - 1 rn,
FIRST_VALUE(numbering) OVER (PARTITION BY node_level ORDER BY tree_seq) first_numbering
FROM yourtable)
ORDER BY tree_seq