Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Change a variable based on the results Expand / Collapse
Author
Message
Posted Thursday, December 16, 2010 3:16 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Friday, February 08, 2013 2:05 AM
Points: 37, Visits: 164
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
Post #1035716
Posted Thursday, December 16, 2010 3:39 AM


SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Today @ 6:04 AM
Points: 240, Visits: 2,389
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
Post #1035727
Posted Thursday, December 16, 2010 4:11 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Friday, February 08, 2013 2:05 AM
Points: 37, Visits: 164
Excellent. Thanks for your help.

Post #1035737
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse