counting number of dys in a specified month

  • IF Exists (

    select 1 where month(getdate()) IN (1,3,5,7,8,10,12)

    )

    i am not getting the solution for the error which this code is generting, can any one help me.

    Shiv

  • You don't have a "source" defined to apply the WHERE clause to. Your source is a table with one row and one column holding the month of getdate():

    IF Exists (

    SELECT 1 FROM (SELECT month(getdate()) AS col) tbl WHERE col IN (1,3,5,7,8,10,12)

    )

    PRINT 'yes'

    ELSE

    PRINT 'no'

    But wouldn't it be easier to evaluate the function in the first place?

    IF month(getdate()) IN (1,3,5,7,8,10,12)

    PRINT 'yes'

    ELSE

    PRINT 'no'



    Lutz
    A pessimist is an optimist with experience.

    How to get fast answers to your question[/url]
    How to post performance related questions[/url]
    Links for Tally Table [/url] , Cross Tabs [/url] and Dynamic Cross Tabs [/url], Delimited Split Function[/url]

  • LutzM (8/18/2010)


    You don't have a "source" defined to apply the WHERE clause to.

    Does not have to, this is valid

    IF EXISTS (SELECT 1 WHERE MONTH(GETDATE()) IN (1,3,5,7,8,10,12))

    PRINT 'yes'

    ELSE

    PRINT 'no'

    Far away is close at hand in the images of elsewhere.
    Anon.

  • tkshiv20 42687 (8/18/2010)


    IF Exists (

    select 1 where month(getdate()) IN (1,3,5,7,8,10,12)

    )

    i am not getting the solution for the error which this code is generting, can any one help me.

    Shiv

    What error are you getting? The code you posted works fine.

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

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