question

danfangdango2 avatar image
danfangdango2 asked

calculating dates in dfa manner

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/2013
toNode 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.
tsqlsearchalgorithm
1 comment
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

can you explain in a bit more detail, and give examples of what result you need
0 Likes 0 ·
Fatherjack avatar image
Fatherjack answered
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
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

ecomma avatar image
ecomma answered
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())
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.