Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2004
    Posts
    17

    Unanswered: Any equivalent for NEXT_DAY fn of Oracle

    Haii Friends,
    Is there any equivalent for Oracle's NEXT_DAY function in sqlserver.I need it for the following query...

    SELECT NEXT_DAY( SYSDATE ,'THURSDAY') FROM DUAL;

    ur Help in this regard is really appreciated....

    Regards,
    Vicky

  2. #2
    Join Date
    Sep 2004
    Posts
    22
    I'm thinking that this query returns you the upcoming Thursday? There's not an immediate function that will easily do this for you, however, either a proc or function can achieve this easily. This is assuming you always want the upcoming Thursday

    Code:
    CREATE PROCEDURE dbo.getNextThursday AS 
    
    DECLARE @CurrentDate AS DATETIME
    DECLARE @DayOfWeek AS TINYINT
    
    SELECT @DayOfWeek = DATEPART(WEEKDAY, GETDATE())
    
    IF (@DayOfWeek < 5) -- Not equal to Thursday
    BEGIN
    	SELECT @CurrentDate = (GETDATE() + (5-@DayOfWeek))
    END
    ELSE
    BEGIN
    	SELECT @CurrentDate = (GETDATE() + (7-(@DayOfWeek-5)))
    END
    
    SELECT @CurrentDate
    
    GO

Posting Permissions

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