Hi,
I have two tables and I need to write a recursive function.
PRODUCT with columns
PRODUCT_ID varchar(50), PRIMARYKEY and
PRODUCT_GROUP_ID varchar (200)
PRODUCT_GROUP with columns
PRODUCT_GROUP_ID varchar(50), PRIMARY KEY and
PRODUCT_UPPER_GROUP_ID varchar (200)
Here is data for PRODUCT table:
PRODUCT_ID PRODUCT_GROUP_ID
SonyTFT3500 SonySiyah
and here is the data for PRODUCT_GROUP table:
PRODUCT_GROUP_ID PRODUCT_UPPER_GROUP_ID
Elektronik, null
Ev Elektroniği, Elektronik
TV, Ev Elektroniği
Sony, TV
SonySiyah, Sony
Except Elektronik, all the other
PRODUCT_GROUP_IDs
have an upper node. What I need is a function given a
PRODUCT_ID = 'SonyTFT3500'
which returns something like this:
temp = "Elektronik > Ev Elektroniği > TV > Sony > SonySiyah".
temp2 = "Elektronik > Ev Elektroniği > TV > Sony > SonySiyah > subnode > subnode > .. > ... > ...."
You can think of
PRODUCT_GROUP_ID
as a parentcategory which might have a category and category might have a subcategory and subcategory has its own subcategory and this goes like this indefinitely.
How do I write a recursive function in Sql Server 2008 so that I get this string temp ?