how to apply parent child relation in my website thru sql - sql

scenario is like
customer_profile
parent child
100 101
100,101 102
100,101,102 103
i have a problem i have chaining system in my asp.net website,when a record has inserted each time it's parent is selected by dropdown list, i want it'll go to various level it's parent of parent's will be concatenated thru sql.
please tell me how to design stored procedure for this chaining.
Thanks in adv

Related

LightSwitch dynamic cascading dropdown lists

In lightswitch, I need to make dynamic cascading dropdown lists based on a recursive relationship:
Table "Categories" includes:
Id
Name
ParentId
here is the desired scenario:
a screen showing a drop down list for the categories with no parent
(ParentId = Null).
once user selects a specific category, another
drop down to be created which includes the selected category
children.
User can select another child category, and show another
dynamic dropdown, and so on till we have categories drop down with
no children.
Thanks & I really appreciate your help with this.
I miss also tree controls in lightswitch, for this reason, I have developed my own:
LightSwitch Custom Control: Tree CRUD Operations
LightSwitch Custom Control: Tree lookup Operations
Be free to get source code and video samples from this links.
Here my control playing with a 2,4Millions nodes tree

Displaying deeper levels programmatically in a Oracle APEX tree hierarchy

I have a situation where I am going to have a fairly large dataset that I need to represent as a tree hierarchy within Oracle APEX v4.2.2. The dataset might be up to 6000 records with a depth of 5 levels.
Based on another thread, what I am looking at doing and this being the reason of this question, is initially within my tree query, I will only display up to 2 levels, i.e.:
WHERE level <= 2
My question is, while displaying my tree hierarchy of level <= 2, I want to then allow the user to click on a level 2 node, which would be fed somehow back into my tree hierarchy query and then basically display from a level 2 node down the tree to say the next 2 levels - now displaying from level 2 to level 4 and then continue in the same fashion.
Obviously I will also need a means of getting back to the top level of my tree from any lower levels being displayed at the time - say from level 4.
I am interested in how to best tackle this - I was also thinking whether I display a popup window of the next set of tree hierarchy data.
I think 6k records is still manageable by Javascript, so probably the easiest way would be to load the entire tree and collapse it onLoad with a Javascript/JQuery dynamic action.
Otherwise you can also try storing the desired level/key on a Hidden Page Item, build the tree hierarchy query using the value from this page item and just refresh the area with a dynamic action onClick.

Is it possible to create a link type in TFS 2010 to be specific what kind of work item is the target and what is the source

For example, I create level 1 2 3 three types of work items. then I want to customize a link type which only link level 1 to level 2, but can`t level 1 to level 3 directly. Is it possible? How?
This is not possible at least from looking at the attributes of a linktype which are referenceName, ForwardName, ReverseName and TopologyType. You can enforce a parent/child relationship that isn't circular but I don't believe you can say "and do not allow this WI type to be a child of this WI when linking."
You do have the ability to create custom link types; however, that will only insure a relationship and not scope it to work item type.
For example, out of the box the CMMI template you can create a bug that has a child of WI Requirement of type Scenario which typically isn't a supported workflow (and isn't if you are trying to be CMMI compliant).
I would take a look at Working with Link Types.

Search products with parent and child categories

I'm building a shopping cart website and using SQL tables
CATEGORY
Id int,
Parent_Id,
Description varchar(100)
Data:
1 0 Electronics
2 0 Furniture
3 1 TVs
4 3 LCD
5 4 40 inches
6 4 42 inches
PRODUCTS
Id int,
Category_Id int
Description...
Data:
1 5 New Samsung 40in LCD TV
2 6 Sony 42in LCD TV
As you can see I only have one column for the last Child Category
Now what I need to do is search by Main Category at homepage, for example if the user clicks to Electronics, show both TVs as they have a Parent-Parent-Parent Id at Electronics, keeping in mind that Products table do have only one column for Category.
Shall I update the Products Table and include 6 columns for category childs in order to solve this? Or how can I build an effective SQL Stored Procedure for this?
Thank you
Jerry
in Oracle, you would use CONNECT BY
If you're using SQL 2008 then you might want to look at the HIERARCHYID data type. Otherwise, you might want to consider redesigning the Category table. How you have it modeled now, you have to use recursion to get from children notes to parents or from parents down through children.
Instead of using the linked list model (which is what you have) you could use the nested set model for hierarchies. Do a search on Joe Celko and Nested Set Model and you should be able to find some good descriptions of it. He also wrote an entire book on modeling trees and hierarchies in SQL. The nested set model requires a bit of set up to maintain the data, but it's much easier to work with when selecting out data. Since your categories will probably remain relatively stable it seems like a good solution.
EDIT: To actually answer your question... you could write a stored procedure that sits in a WHILE loop, selecting children and collecting any products found in a table variable. Check ##ROWCOUNT in each loop and if it's 0 then you've gotten to the end. Then you just select out from your table variable. It's a recursive (and slow) method, which is why this type of a model doesn't work very well in many cases in SQL.
Under almost no circumstances should you just add 6 (or 7 or 8) category IDs to your products table. Bad. Bad. Bad. It will be a maintenance nightmare among other things (what happens when your categories go 7 levels deep... then 8... then 9.
Use recursive CTEs to do this ! works like a dream ! http://msdn.microsoft.com/en-us/library/ms186243.aspx

CONNECT_BY_ISLEAF with Conditions

I have a hierarchical set-up going on a table using the whole START WITH and CONNECT BY clauses, which I am using to set-up a vertical-aligned menu system that can expand out to the right, depending on if a menu option has children and the total number of Levels. Also, as part of the menu option, if a parent has children, I also display a '>' symbol to specify this.
My question is, I am using CONNECT_BY_ISLEAF to determine whether a menu option is a leaf or not but I also have a column in my hierarchical table that specifies whether the menu option is active or not.
So when I have a case of a parent/child set-up in my menu, so that the ISLEAF value for Parent is 0 and Child is 1, but I have actually made the Child menu option inactive, my '>' symbol still displays at the parent level, even though the child record for this parent is inactive.
Any idea how I can check this alongside with the CONNECT_BY_ISLEAF value, to prevent the '>' symbol appearing even though this parent menu option has an inactive child record?
Basically want something that, if a child record exists based on ISLEAF value but child record is inactive, then ignore this leaf record and pretend it doesn't actually exist.
SELECT *
FROM table
CONNECT BY
parent = PRIOR id
AND active = 1
This will select a child only if it's active, if that's what you want.
Note that this query will return CONNECT_BY_ISLEAF = 1 for the items that do not have active children, and they will probably be treated as endpoints in your design.