locked
Comparing int to getdate() RRS feed

  • Question

  • I need to compare a column with type int to the current year and next year. Right now I have it as following:

    SELECT username FROM someTable WHERE membershipYear = DATEPART(yyyy, GETDATE()) OR membershipYear = DATEPART(yyyy, GETDATE()+1)
    
    

    I am unsure if I can compare membershipYear (int type) and GETDATE() (date type). Also, I don't even know if GETDATE()+1 is a valid statement for getting the next year. I usually would just test and troubleshoot from there, but this is live and the procedure is currently tied to a login. I don't just want to push something that will cause it to break.

     Thanks in advance for your understanding and help.
    Tuesday, September 15, 2009 7:44 PM

Answers

  • this will do

    SELECT username FROM someTable WHERE membershipYear = DATEPART(YEAR, GETDATE()) 
    OR membershipYear = datepart(yyyy,DATEADD(YEAR, 1, getdate()))

    Best Regards,
    Melissa Suciadi


    If you have found this post helpful, please click the 'Vote as Helpful' link (the green triangle and number on the top-left).

    If this post answers your question, click the 'Mark As Answered' link below. It helps others who experience the same issue in future to find the solution.

    • Proposed as answer by Melissa Suciadi Wednesday, September 16, 2009 1:12 AM
    • Marked as answer by David Entner Monday, September 21, 2009 6:02 PM
    Wednesday, September 16, 2009 12:37 AM