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.
Author |
Topic |
ktech
Starting Member
7 Posts |
Posted - 2014-02-12 : 21:15:34
|
Hi,I have another parameter question.I need create a parameter for users to select the year, then pass the parameter to a store procedure, when the sp invoke a function, then use it as part of datetime.For example the parameter is @Year, when user select Year2014, integer 14 is passed to the function, then @startdate = '10/1/@year'. Before use the parameter, the startdate is set as '10/1/14', now we want to do it dynamically. How can I use the parameter @Year as part of datetime.Thank you so much for any helps!! |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2014-02-13 : 08:17:36
|
you dont need to do like thst. just pass 2014 as value itself and use logic like below to get required dateDECLARE @Year int = 2014SELECT DATEADD(dd,9,DATEADD(yy,@Year-1900,0)) ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
ktech
Starting Member
7 Posts |
Posted - 2014-02-13 : 08:33:15
|
visakh16,Thank you again!!!That works! So for the enddate, I can do SELECT DATEADD(mm,11,DATEADD(yy,@Year-1900,30)) to get 12/31/2014 and so on...Very nice!!Thank you so much!! |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2014-02-13 : 12:29:02
|
yep..indeed------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
|
|
|
|
|