Insert based on date

  • 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

  • earlier : dateadd(m, -6, DateField)

    later : dateadd(m, 6, DateField)

  • Thank you !!! so would it be

     

    insert fieldname dateadd(m, -6, Datefield)

  • 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))

  • 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. 

  • remove , DateCol and ,@DateCol

    You know how to do an insert statement right??

  •  

    Simple insert

    INSERT INTO tbTest (field1, field2, field3, field4) VALUES ('1', '1', '1',

    '1')

     

     

  • Cool, post again if you need further assistance.

  • I m still messed up

     

    Insert into sunrise (Poc, Sunset, DateBefore, DateAfter) values (@Poc, @Sunset, dateadd(m, -6, Datefield), dateadd(m, 6, Datefield))

  • 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

     

  • 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

     

  • 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

  • Insert into sunrise (Poc, Sunset, DateBefore, DateAfter) values (@Poc, @Sunset, dateadd(m, -6, Production), dateadd(m, 6, Production))

    Server: Msg 137, Level 15, State 2, Line 1

    Must declare the variable '@Poc'.

  • 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!!!!!

  • 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