December 16, 2010 at 3:16 am
Hi,
I am trying to change a variable based on the results of the same variable. Is this possible or do I need to go about this some other way.
Code below:
DECLARE @NextMonth AS nvarchar(7)
SET @NextMonth = LEFT(datename(mm, dateadd(month, 1, GETDATE())), 3) + '-' + RIGHT(datename(yy, getdate()), 2)
if @nextmonth = 'Jan-10' then @NextMonth = LEFT(datename(mm, dateadd(month, 1, GETDATE())), 3) + '-' + RIGHT(datename(yy, getdate()),+1, 2)
else s @NextMonth = LEFT(datename(mm, dateadd(month, 1, GETDATE())), 3) + '-' + RIGHT(datename(yy, getdate()), 2)
select @nextmonth
December 16, 2010 at 3:39 am
DECLARE @NextMonth AS nvarchar(7)
SET @NextMonth = LEFT(datename(mm, dateadd(month, 1, GETDATE())), 3) + '-' + RIGHT(datename(yy, getdate()), 2)
if @nextmonth = 'Jan-10'
set @NextMonth = LEFT(datename(mm, dateadd(month, 1, GETDATE())), 3) + '-' + RIGHT(datename(yy, getdate())+1, 2)
else
set @NextMonth = LEFT(datename(mm, dateadd(month, 1, GETDATE())), 3) + '-' + RIGHT(datename(yy, getdate()), 2)
select @nextmonth
--------------------------------------------------------------------------------------------------
I am just an another naive wannabe DBA trying to learn SQL Server
December 16, 2010 at 4:11 am
Excellent. Thanks for your help.
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply