I have used CTEs, but never for what I have heard they are good at and now I have a circumstance where I need to find a value recursively. I have a table of specimens, both parent and child (and grandchild and great grandchild etc.) from which I need to find some relationships. For instance, each specimen (specimenid) has a specimen type (specimentypeid) and a parentid (which is blank if it is the first parent). So, specimen A can be processed and specimen x2 created, then specimen x2 is processed and specimen d8 is created. For another specimen B it may be processed and t5 is created. Let's say that I need to take every specimentypeid=12 and find every one with a parent (either immediate or final) with specimentypeid=2. How do I build a recursive CTE that will search through the entire table and start with one specimen type then search up the chain until it hits the top (parentid is null) for the specimen chain and then restrict by speciemntypeid?
Thanks,
Willie
Thanks,
Willie