June 10, 2005 at 12:28 pm
trying to insert a date based on another date in another field. I need to insert a date 6 months older in one and 6 months new in another.
Any thoughts hints?
Thanks
June 10, 2005 at 12:36 pm
earlier : dateadd(m, -6, DateField)
later : dateadd(m, 6, DateField)
June 10, 2005 at 12:40 pm
Thank you !!! so would it be
insert fieldname dateadd(m, -6, Datefield)
June 10, 2005 at 12:49 pm
hmm not exactly,
(assuming you're gonna create a stored proc to do the insert) :
Insert into dbo.YourTable (Col1, Col2, DateCol, DateBefore, DateAfter) values (@Col1, @Col2, DateCol, dateadd(m, -6, Datefield), dateadd(m, 6, Datefield))
June 10, 2005 at 12:54 pm
Just need to do one bult update on two fields
POC is the 6 months older field
Sunset is the 6 month newer
Sorry I am super new to dealing with dates.
June 10, 2005 at 12:57 pm
remove , DateCol and ,@DateCol
You know how to do an insert statement right??
June 10, 2005 at 1:11 pm
Simple insert
INSERT INTO tbTest (field1, field2, field3, field4) VALUES ('1', '1', '1',
'1')
June 10, 2005 at 1:22 pm
Cool, post again if you need further assistance.
June 10, 2005 at 1:40 pm
I m still messed up
Insert into sunrise (Poc, Sunset, DateBefore, DateAfter) values (@Poc, @Sunset, dateadd(m, -6, Datefield), dateadd(m, 6, Datefield))
June 10, 2005 at 1:43 pm
Datefield is the value that you base your calculations on. I was under the impression that this also was a column in the table.
Here's #2000
June 10, 2005 at 1:46 pm
hey I got you to 2K COOL!!!
Yes one field is the one I need to pull the up or down dates from
Production
Thanks
Mike
June 10, 2005 at 1:49 pm
Sorry, should have asked this earlier.
This is something that you do NOT keep in the db since it can be calculated easyly.
Select Production, dateadd(m, -6, Production) as Before, dateadd(m, +6, Production) as After from dbo.YourTableNameHere
June 10, 2005 at 1:57 pm
Thank You!!! Yes that's the correct way and I missed it to during the creating of the table. Thinking to much. If you have the ONE date that's constant then you can CREATE others via the select. Then create the SP to run when I call it in .NET.
THANK YOU!!!!!
June 10, 2005 at 2:04 pm
NP... the simpler the better .
Viewing 15 posts - 1 through 14 (of 14 total)
You must be logged in to reply to this topic. Login to reply