Qlik Community

New to QlikView

Discussion board where members can get started with QlikView.

Announcements
Talk to Experts Tuesday, Live Q&A, September 22: Moving from QlikView to Qlik Sense. REGISTER
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Contributor
Contributor

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
Highlighted
Partner
Partner

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.

Highlighted
Contributor III
Contributor III

Nick,

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

Highlighted
Specialist II
Specialist II

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

Highlighted
Contributor
Contributor

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

Highlighted
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?