Query by Year

  • I have over 400 records that range from the year 2008 to 2005. I need to get data within a specific year. Please help.

    SELECT CONVERT(varchar, Event.EventDate, 110) AS Date, Player.PlayerFName AS Players, Scard.Ranking AS Ranking

    FROM Scard INNER JOIN

    Event ON Scard.EventID = Event.EventID INNER JOIN

    Player ON Scard.PlayerID = Player.PlayerID

    WHERE

  • declare @yearnum int

    set @yearnum=2008

    set @yearnum=@yearnum-1900

    SELECT CONVERT(varchar, Event.EventDate, 110) AS Date, Player.PlayerFName AS Players, Scard.Ranking AS Ranking

    FROM Scard INNER JOIN

    Event ON Scard.EventID = Event.EventID INNER JOIN

    Player ON Scard.PlayerID = Player.PlayerID

    WHERE

    Event.eventdate >= dateadd(year,@yearnum,0) and Event.eventdate < dateadd(year,@yearnum+1,0)

    ----------------------------------------------------------------------------------
    Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?

  • I copied the codes you provided and got the following error message:

    Must declare the scalar variable "@year"

    Thanks for your help.

  • gtan018 (5/9/2008)


    I copied the codes you provided and got the following error message:

    Must declare the scalar variable "@year"

    Thanks for your help.

    You must not have copied something right - my variable is @yearnum. Take a second look - if you're still stuck - paste the updated code....

    ----------------------------------------------------------------------------------
    Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?

  • You are correct. Somehow I had @yearnum twice. You are the man.

    Thanks for your quick response and knowledge.

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

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