Skip to main content
Announcements
Global Transformation Awards! Applications are now open. Submit Entry
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

How do I set the value of a variable based on the value of another variable in an IF THEN statement?

I was trying to do a simple series of set variable statements based on the value of another variable, like this:

IF $(vCurrentYear) = "2013-14" THEN

SET vPrevYear = "2012-13";

IF $(vCurrentYear) = "2014-15" THEN

SET vPrevYear = "2013-14";

But these cause the script to load nothing at all, and an hour of Googling hasn't gotten me anywhere. This seems like it should be a very simple thing. Is there a better way to do this? Thanks in advance!

1 Solution

Accepted Solutions
jagan
Luminary Alumni
Luminary Alumni

Hi Shawn,

Try like this

SET vCurrentYear = '2013-14';

IF vCurrentYear = '2013-14' THEN

  SET vPrevYear = '2012-13';

ELSEIF vCurrentYear = '2014-15' THEN

  SET vPrevYear = '2013-14';

END IF;

Regards,

Jagan.

View solution in original post

4 Replies
Not applicable
Author

make it

if  '$(vCurrentYear)'='2013-14' then

    set......

if '$(vCurrentYear)'='2014-15'

Your variable stores a string so the Dollar sign expansion needs to be enclosed within single quotes.

jagan
Luminary Alumni
Luminary Alumni

Hi Shawn,

Try like this

SET vCurrentYear = '2013-14';

IF vCurrentYear = '2013-14' THEN

  SET vPrevYear = '2012-13';

ELSEIF vCurrentYear = '2014-15' THEN

  SET vPrevYear = '2013-14';

END IF;

Regards,

Jagan.

fkeuroglian
Partner - Master
Partner - Master

Hi, try this

set vCurrentYear ='2013-14';

IF '$(vCurrentYear)' = '2013-14' THEN

  SET vPrevYear = '2012-13';

  IF $(vCurrentYear) = '2014-15' THEN

  SET vPrevYear = '2013-14';

  END if

end if

good luck!

Fernando

Not applicable
Author

Worked perfectly.

Thanks so much, Jagan!