Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Declaring year as a parameter

Author  Topic 

divan
Posting Yak Master

153 Posts

Posted - 2013-05-28 : 09:58:24
I need to create a stored procedure usp_run_written_premium where I only use year portion of the POL_EFF_DATE as a parameter..


I know that I can write
CREATE usp_run_written_premium @date datetime as
.
.
.
.
.

but with this declaration I will need to enter month,day, and year when I run the script

I would like to run the the procedure like such

usp_run_written_premium '2009'




James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-05-28 : 10:22:10
Change the signature of your stored proc to:
CREATE usp_run_written_premium @year int AS
....
Then change the code in the stored proc appropriately, for example:
WHERE 
POL_EFF_DATE >= DATEADD(yy,@year-1900,0)
AND POL_EFF_DATE < DATEADD(yy,@year-1899,0)
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-05-28 : 14:20:31
Explanation you can see here

http://visakhm.blogspot.in/2012/07/generate-datetime-values-from-integers.html

http://visakhm.blogspot.in/2012/12/different-ways-to-implement-date-range.html

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -