Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2005
    Location
    Portland, Oregon
    Posts
    40

    Unanswered: Automate "Week Ending" Date

    How do i automate, by stored procedure, generating the "week ending" date using a field data.

    ------------------------------------------------------------

    CREATE TABLE [dbo].[t_Work_Hours] (
    [WorkHoursID_PK] [int] IDENTITY (1, 1) NOT NULL ,
    [PeopleID_FK] [int] NOT NULL ,
    [JobID_FK] [int] NULL ,
    [StartTime] [datetime] NULL ,
    [EndTime] [datetime] NULL ,
    [Title] [nvarchar] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
    [WeekEnding] [datetime] NULL ,
    CONSTRAINT [PK_t_Work_Hours] PRIMARY KEY CLUSTERED
    (
    [WorkHoursID_PK]
    ) ON [PRIMARY] ,
    CONSTRAINT [FK_t_Work_Hours_t_Work_People] FOREIGN KEY
    (
    [PeopleID_FK]
    ) REFERENCES [dbo].[t_Work_People] (
    [PeopleID_PK]
    )
    ) ON [PRIMARY]
    GO
    -------------------------------------------------------

    What i have tried has'nt even been close to a solution.
    UPDATE dbo.t_Work_Hours
    SET WeekEnding = DATETIME ( ??? , StartTime) . I have no idea where to go!

    ----------------------------------------------------------------
    WorkHoursID_PK, PeopleID_FK, JobID_FK, StartTime, EndTime, Title, WeekEnding
    7, 40, 3, 11/1/2005 6:00:00 AM, 11/1/2005 4:30:00 PM, J, (NULL)
    8, 43, 3, 10/31/2005 6:00:00 AM, 10/31/2005 4:30:00 PM, F, 11/6/2005 11:59:00 PM
    9, 43, 3, 11/1/2005 6:00:00 AM, 11/1/2005 4:30:00 PM, F, 11/6/2005 11:59:00 PM
    -----------------------------------------------------------
    Last edited by hildebran; 11-04-05 at 00:42.

  2. #2
    Join Date
    Jul 2003
    Location
    San Antonio, TX
    Posts
    3,662
    If you insist on performing an UPDATE on the field, then some variation of the statement below should suffice:


    ...SET WeekEnding =dateadd(day, 8-datepart(dw, StartTime), StartTime)...


    I would make WeekEnd a computed column like this:

    alter table add Weekend as dateadd(day, 8-datepart(dw, StartTime), StartTime)
    "The data in a record depends on the Key to the record, the Whole Key, and
    nothing but the Key, so help me Codd."

  3. #3
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

  4. #4
    Join Date
    Oct 2001
    Posts
    46

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •