Hi, i'm a litte bit new to all this with programming and database queryes.
But i have a question: Is it possible when you do a INSERT to also INSERT it to Parent items?
sry now i see i explained it all really wrong =/
what i really want to do is to INSERT into a diffrent table using all the parent items.
i have the list
ID
INFO
ParentID
8
Products
Null
9
Fruits
8
10
Bananas
9
This list is used for a menu and i can then "create" pictures for a specific menu item
so the user can choose to insert a picture under any of thoose menu items.
And if he choose a item with a Parent item i want to use the information from the parent items
to create the picture he wanted for the child item in all the parent items.
so i have the above table that is a menu and then i have this table that should get the outpot like this:
ID
Picture
Ref_INFO
100
Bananas picture
Bananas
101
Bananas picture
Fruits
102
Bananas picture
Products
so when i add a picture for bananas i want it to be added to all the parent items to , so when i Press Products in the menu there should be a banana picture , if i press Fruits there should be a Banana Picture , if i press Bananas there should be a banana
picture
if i press another item in the menu let's say i have another item under Fruits that's called Coconuts there shouldnt be a banana picture showing but in all of bananas parent items it should.
well i dont really know how to do it since i have two parent ids, i want to insert in all parent items,
so i want to insert info into 10,9 and 8 but i dont really know how to do that =)
could you give an example? please
sry now i see i explained it all really wrong =/
what i really want to do is to INSERT into a diffrent table using all the parent items.
i have the list
ID
INFO
ParentID
8
Products
Null
9
Fruits
8
10
Bananas
9
This list is used for a menu and i can then "create" pictures for a specific menu item
so the user can choose to insert a picture under any of thoose menu items.
And if he choose a item with a Parent item i want to use the information from the parent items
to create the picture he wanted for the child item in all the parent items.
so i have the above table that is a menu and then i have this table that should get the outpot like this:
ID
Picture
Ref_INFO
100
Bananas picture
Bananas
101
Bananas picture
Fruits
102
Bananas picture
Products
so when i add a picture for bananas i want it to be added to all the parent items to , so when i Press Products in the menu there should be a banana picture , if i press Fruits there should be a Banana Picture , if i press Bananas there should be a banana
picture
if i press another item in the menu let's say i have another item under Fruits that's called Coconuts there shouldnt be a banana picture showing but in all of bananas parent items it should.
I have solved this by looping a function to check if there is a parentID and then add for that item aswell and then loop the function again to with the new parentID and check if that item has a parentID and then add it and so on
but i was woundering if there is a simpler way of doing this
I dont think that there is any possibility using Insert statement only
it could be done using TSQL having to write some smart stored procedure, as I dont know wether
Insert can be used recursively or not.
But there must be some TSQL logic for that
SKDl
Member
202 Points
208 Posts
Question about INSERT and Relations
Dec 14, 2012 06:34 AM|LINK
Hi, i'm a litte bit new to all this with programming and database queryes.
But i have a question: Is it possible when you do a INSERT to also INSERT it to Parent items?
sry now i see i explained it all really wrong =/
what i really want to do is to INSERT into a diffrent table using all the parent items.
i have the list
This list is used for a menu and i can then "create" pictures for a specific menu item
so the user can choose to insert a picture under any of thoose menu items.
And if he choose a item with a Parent item i want to use the information from the parent items
to create the picture he wanted for the child item in all the parent items.
so i have the above table that is a menu and then i have this table that should get the outpot like this:
so when i add a picture for bananas i want it to be added to all the parent items to , so when i Press Products in the menu there should be a banana picture , if i press Fruits there should be a Banana Picture , if i press Bananas there should be a banana picture
if i press another item in the menu let's say i have another item under Fruits that's called Coconuts there shouldnt be a banana picture showing but in all of bananas parent items it should.
sorry about the other earlier post.
usman400
Contributor
3503 Points
721 Posts
Re: Question about INSERT and Relations
Dec 14, 2012 06:42 AM|LINK
Ok u said u appreciate any posts so I did
usman400
Contributor
3503 Points
721 Posts
Re: Question about INSERT and Relations
Dec 14, 2012 06:43 AM|LINK
Moreover,
Seems a simple parent-child records scenario
so go ahead store the parent id whats the problem ?
I dont understand when you said:
and now i want to insert something for id 10
but i also want part of the same info to appear in it's parent nodes
SKDl
Member
202 Points
208 Posts
Re: Question about INSERT and Relations
Dec 14, 2012 06:51 AM|LINK
well i dont really know how to do it since i have two parent ids, i want to insert in all parent items,
so i want to insert info into 10,9 and 8 but i dont really know how to do that =)
could you give an example? please
SKDl
Member
202 Points
208 Posts
Re: Question about INSERT and Relations
Dec 14, 2012 07:14 AM|LINK
sry now i see i explained it all really wrong =/
what i really want to do is to INSERT into a diffrent table using all the parent items.
i have the list
This list is used for a menu and i can then "create" pictures for a specific menu item
so the user can choose to insert a picture under any of thoose menu items.
And if he choose a item with a Parent item i want to use the information from the parent items
to create the picture he wanted for the child item in all the parent items.
so i have the above table that is a menu and then i have this table that should get the outpot like this:
so when i add a picture for bananas i want it to be added to all the parent items to , so when i Press Products in the menu there should be a banana picture , if i press Fruits there should be a Banana Picture , if i press Bananas there should be a banana picture
if i press another item in the menu let's say i have another item under Fruits that's called Coconuts there shouldnt be a banana picture showing but in all of bananas parent items it should.
sorry about the other posts.
SKDl
Member
202 Points
208 Posts
Re: Question about INSERT and Relations
Dec 14, 2012 08:35 AM|LINK
I have solved this by looping a function to check if there is a parentID and then add for that item aswell and then loop the function again to with the new parentID and check if that item has a parentID and then add it and so on
but i was woundering if there is a simpler way of doing this
usman400
Contributor
3503 Points
721 Posts
Re: Question about INSERT and Relations
Dec 14, 2012 08:52 AM|LINK
I dont think that there is any possibility using Insert statement only
it could be done using TSQL having to write some smart stored procedure, as I dont know wether
Insert can be used recursively or not.
But there must be some TSQL logic for that
SKDl
Member
202 Points
208 Posts
Re: Question about INSERT and Relations
Dec 14, 2012 11:02 AM|LINK
ok thank you i will look into it =)