Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need query logic help 1

Status
Not open for further replies.

sparkme

Programmer
Oct 3, 2003
30
US
Can someone help me in this.....

Table name-customer

Customerid custname flag parentid
1 A I 0
2 P I 0
3 B S 1
4 Y S 5
5 X I 0
6 z S 5
7 c S 1
8 R S 2
9 Q S 2


output should be like this:
parent and then its childs again parent and its childs
like these,parent1,child of parent 1,child of parent 1,parent 2,child of parent 2 ,child of parent 2

EXAMPLE :
Customerid custname flag parentid
1 A I 0
3 B S 1
7 c S 1
2 P I 0
8 R S 2
9 Q S 2
5 X I 0
4 Y S 5
6 z S 5

Thanks
 
select Customerid,custname,flag,parentid
from
name-customer
order by (case
when parentId=0 then custumerId
else parentId end),parentId

--------------------------------------------------
[highlight]Django[/highlight] [thumbsup]
bug exterminator
tips'n tricks addict
 
Hi Django,
It works, Thanks you, You are great.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top