Case when statement

  • How can I accomplish this?

    select case when Datename(dw,getdate()) = 'Sunday' then

    set @dateBegin = Getdate()),

    set @date2 = dateadd(dd,1,getdate())

    Thanks.

  • TSQL CASE is not the same as other programming languages...

    in SQL, CASE is used to return data...to make logical decisions, you have to use IF.ELSE

    How can I accomplish this?

    IF Datename(dw,getdate()) = 'Sunday'

    BEGIN

    set @dateBegin = Getdate()),

    @date2 = dateadd(dd,1,getdate())

    END

    ELSE

    BEGIN

    'so something..

    PRINT 'other WORK

    END

    How can I accomplish this?

    select

    case

    when Datename(dw,getdate()) = 'Sunday'

    then Getdate()),

    ELSE dateadd(dd,1,getdate())

    END

    Thanks.

    Thanks.

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Thank you much. That works.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply