Author |
Topic |
kappa02
Yak Posting Veteran
65 Posts |
Posted - 2014-10-17 : 12:32:58
|
Is there a way which I can take the three statements below and merge them into one? maselect @twomnthmaildate = STUFF(CONVERT(varchar(12),DATEADD(month,2,getdate()),107),1,3,DATENAME(MM,DATEADD(month,2,getdate())))select @maildate = @twomnthmaildate -7SELECT @maildate = DATENAME(MM, @maildate) + RIGHT(CONVERT(VARCHAR(12), @maildate, 107), 9) |
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2014-10-17 : 12:41:08
|
I just did a copy/paste. I'm not sure that it makes code sense to put them into one when it makes it harder to read. Make sure you add a good comment to your code.SELECT @maildate = DATENAME(MM, STUFF(CONVERT(varchar(12),DATEADD(month,2,getdate()),107),1,3,DATENAME(MM,DATEADD(month,2,getdate()))) -7) + RIGHT(CONVERT(VARCHAR(12), STUFF(CONVERT(varchar(12),DATEADD(month,2,getdate()),107),1,3,DATENAME(MM,DATEADD(month,2,getdate()))) -7, 107), 9)Tara KizerSQL Server MVP since 2007http://weblogs.sqlteam.com/tarad/ |
|
|
ScottPletcher
Aged Yak Warrior
550 Posts |
Posted - 2014-10-17 : 12:42:02
|
[code]SELECT DATENAME(month, maildate) + RIGHT(CONVERT(VARCHAR(12), maildate, 107), 9)FROM (SELECT DATEADD(DAY, -7, DATEADD(month, 2, getdate())) AS maildate) AS x[/code] |
|
|
|
|
|