Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1056471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:43:10+00:00 2026-05-16T17:43:10+00:00

First I need to create a sproc that will give me just a list

  • 0

First I need to create a sproc that will give me just a list of years from this year back to 5 years before this year. I was thinking of somehow using a table variable?

After that I need to use that value as a parameter in another sproc. How would I then say show all Dates that contain the year that is picked? I know how to write the parameter and everything I just need the Where clause part of it.

The date in the column are like this 2010/01/30 00:00.000

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T17:43:11+00:00Added an answer on May 16, 2026 at 5:43 pm

    Part One:

    Declare @Years Table (int year primary Key Not Null)
    Declare @Yr integer Set @Yr = Year(getDate())
    Declare @tYr Integer Set @tYr = @Yr
    while @Yr > @TYr - 5 Begin
       Insert @Years(year) Values (@Yr)
       Set @Yr = @Yr - 1
    End
    

    Part TWO: (I assume you mean “Show all Dates That contain a year in the five year span” ??)

    Where Year(dateColumn) In (Select year from @Years)
    

    — But this is not SARGable, so I would reccomend instead,

    Where dateColumn Between DateAdd(year, Year(getDate())-1905, 0) 
                         And DateAdd(year, Year(getDate())-1899, 0) 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need this roadmap of a Hibernate managed object instance. First, I create an
this is my first post here. I need create a feed like facebook with
Hey all. I need to create an array of first names from another array
I want to program this algorithms in Prolog, and first I need to create
I need to create a page with two portlets. The first one will need
this is my first post so if you need clarificatrion on anything then just
I'm create a deal agregator but first i need to put xpath into database
I just created my first MVC2 project using the standard template. I need to
I'm using Visual Studio 2008 and I need create a DataTable from a Excel
I need to create several id's for several structs. Now I want that each

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.