- Home /

I have one table datecalculation it has the following columns

| toNode | fromNode | days | |---------------------------| | 1 | 12 | 80 | | 3 | 5 | 45 | | 4 | 6 | 54 | ...the toNode is the result and the fromNode gives you the result by adding the amount of days to the fromNode The only date that I have is a created date form another table that in this case will be from node now. Example (first row of 'datecalculation' table)

select createddate from nodes createddate = 01/01/2013 createddate = fromnode 12 fromNode 12 + 80 days = 22/03/2013toNode 1 now has this value and we in the datecalculation table where fromNode is id is 1 and use that to calculate the correlating toNode. Is there a way of traversing this table to get the results in a depth first algortihm manner? Is this possible in tsql? Many thanks in advance.

Comment

can you explain in a bit more detail, and give examples of what result you need

**Answer** by ecomma ·

It would have been much easier if you had provided you db schema. I thinks this would be a good guide declare (type) sum_of_fromNode_and_days=fromNode+days, declare(type) Yourcolomn_in_Question = DateAdd(dd,sum_of_fromNode_and_days,GetDate())

**Answer** by Fatherjack ·

I'm not wholly sure what your problem is or where you are stuck but it is certainly possible to use data from a table to complete a value in a date manipulation function DECLARE @Store TABLE ( ID INT IDENTITY , AddVal INT ) INSERT @store ( AddVal ) VALUES ( 1 ), ( 5 ), ( 20 ), ( 60 ), ( 100 ) SELECT DATEADD(dd, AddVal, GETDATE()) FROM @store

Copyright 2019 Redgate Software.
Privacy Policy

- Anonymous
- Sign in
- Create
- Ask a question
- Spaces
- Site Issues (NOT FOR DATABASE QUESTIONS)
- Explore
- Topics
- Questions
- Users
- Badges