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 |
|
joe8079
Posting Yak Master
127 Posts |
Posted - 2011-11-10 : 21:01:33
|
| I'm trying to return just the year in a date so I can use it as a constant within a variable, but i'm running into problems and i've searched all over the internet. Declare @mydate as datetimeset @mydate = current yearI want @mydate to return only the current year and nothing else because I need to use that variable in the where statement of a select clause. I tried setting @mydate = '2011', but this did not work. any help would be greatly appreciated. thanks, |
|
|
sql-programmers
Posting Yak Master
190 Posts |
Posted - 2011-11-10 : 21:46:47
|
| If you want only the year then declare the variable as INT, not as datetime.Declare @mydate as INTset @mydate = YEAR(GETDATE())SELECT @mydateSQL Server Programmers and Consultantshttp://www.sql-programmers.com/ |
 |
|
|
joe8079
Posting Yak Master
127 Posts |
Posted - 2011-11-10 : 21:51:03
|
| interesting, I will try that tommorow. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-11-11 : 03:35:26
|
| you mean to say that you're storing year,month etc seperately in your table rather than storing date itself?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|