Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

How do you make the yearname function return an int in qlikview

I have some SQL within Qlikview which when I try to run in SQL I get an error:

Conversion failed when converting the varchar value '$(vCurrentYearRAM)' to data type int.

So my variable is currently created like this:


let vCurrentYearRAM = right(YearName(today(),0,3),4);

When I simply change it to the following it works:

let vCurrentYearRAM = '2018';


I also tried the following and this does not work either:


let vCurrentYearRAM = num(right(YearName(today(),0,3),4));


Any ideas?



5 Replies
felipedl
Partner - Specialist III
Partner - Specialist III

HI Nick,

Just use the function without any manipulation, like so:

let vCurrentYearRAM = YearName(Num(Today()));

simpler option is:

let vCurrentYearRAM =Year(Today());

That will return 2018 and when you expand it to the SQL query it should work.

Anonymous
Not applicable
Author

Nick,

What is the value you are getting from the variable? I am getting  "2019"

neelamsaroha157
Specialist II
Specialist II

May be try with Num# like Num(Num#(Right(YearName(today(), 0, 3),4)))

Anonymous
Not applicable
Author

Sorry 2018 was a bad example.

Our fiscal year runs from April, so today the fiscal year is 2018-2019 so would want it to display 2019 really

swuehl
MVP
MVP

I assume your issue arise from something different.

Conversion failed when converting the varchar value '$(vCurrentYearRAM)' to data type int.


Here, the SQL should not 'see' $(vCurrentYearRAM) at all, a dollar sign expansion should have been replaced before sending the code to the SQL driver.

How does your script look like?