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 |
|
GeoffreyP
Starting Member
9 Posts |
Posted - 2009-11-05 : 08:47:48
|
| How do I get the month to be 09Code BelowDeclare @Period varchar(6),@gYear Varchar(4), @gMonth varChar(2),@LongPeriod varChar(30),@LongMonth varchar(20)Select @gYear = Year(getdate()),@gMonth = (Month(getdate()) -2),@Period = @gYear + @gMonth,@LongMonth = DATENAME(MONTH,getdate()),@LongPeriod = @LongMonth + ' ' + @gYearSelect@gYear as [Year],@gMonth as [Month],@Period as Period,@LongMonth as longMth,@LongPeriod as longPeriod |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2009-11-05 : 08:53:27
|
select right('00'+convert(varchar(2),@gMonth),2) as [Month] No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
GeoffreyP
Starting Member
9 Posts |
Posted - 2009-11-05 : 09:03:23
|
| Thanks It works |
 |
|
|
GeoffreyP
Starting Member
9 Posts |
Posted - 2009-11-05 : 09:23:42
|
quote: Originally posted by webfred select right('00'+convert(varchar(2),@gMonth),2) as [Month] No, you're never too old to Yak'n'Roll if you're too young to die.
If it's to loud you'r to old |
 |
|
|
GeoffreyP
Starting Member
9 Posts |
Posted - 2009-11-05 : 09:33:07
|
| Check the line below: does supply correct long month???Year Month Period LongMth LongPeriod2009 09 200909 January January 2009Select @LongMonth = DATENAME(MONTH,(Month(getdate())-2 )), |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2009-11-05 : 09:50:54
|
Not sure what you mean.set language englishselect DATENAME(MONTH,(Month(getdate())-2 ))gives:JanuaryBUT:select datename(month,(dateadd(month,-2,getdate())))gives:September No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
|
|
|
|
|