Results 1 to 9 of 9
  1. #1
    Join Date
    Nov 2006
    Posts
    1

    Unanswered: how to find year from 1900 to 2000 using store procedure in sql server

    hi friends
    i want to know how to calculate year ranging from 1900 to 2000 using store procedure in sql server

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    oh, that's easy

    which year?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Nov 2006
    Location
    UK
    Posts
    46
    What exactly you want to do?
    Regards
    Kris Zywczyk

  4. #4
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    Code:
    create procedure CalculateYearBetween1900And2000(@InputDate datetime)
    as
    begin
    declare	@OutputYear int
    if year(@InputDate) between 1900 and 2000
    	set @OutputYear = year(@InputDate)
    select @OutputYear
    end
    Last edited by blindman; 11-21-06 at 10:00.
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

  5. #5
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    Do you want a random year? Are the day and month important too, or just the year?

    -PatP

  6. #6
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Quote Originally Posted by blindman
    Code:
    ...
    if year(@InputDate) between 1900 and 1000
    ...
    i don't see this returning TRUE very often...
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  7. #7
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    dbforums did not take my original edit. the code has been corrected and should work fine now.
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

  8. #8
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    ah, i understand

    it was one of those edits that disappeared down the same hole that many archived threads have gone...
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  9. #9
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Have you used a select statement for simplicity or would you simply not consider an OUTPUT variable or RETURN year(@InputDate)?
    Testimonial:
    pootle flump
    ur codings are working excelent.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •