When to use $(variable) and when just to use variable?
I'm a bit confused on when to use $(variable) and when just to use variable. I have the following script;
For vYear = 2010 to 2015
For vMonth = 1 to 12
vMonth = vYear & NUM(vMonth,'00')
But should that bolded line be vMonth = $(vYear) & NUM ($(vMonth),'00')?
As far as I can tell they do the same thing (in this instance).
I understand that $(variable) is saying "don't interpret this as a literal string" but that doesn't always matter, so is it just a matter of "best practice" to always use $(variable) or is there actually different functionality?
Re: When to use $(variable) and when just to use variable?
This expression is OK as a let expression. No need for the expansion here.
Let vMonth = vYear & NUM(vMonth,'00');
Expansions are necessary in SQL expressions because the database server has no concept of QV variables. Expansions are also necessary in set expressions and sometimes when you need to inject some dynamic text into a statement.
In the front end, if the variable is defined with a leading =, then it is globally evaluated and it can be used without an expansion (it already contains the result of the expression). If not, then you need to inject the variable into the expression using a $ expansion. For example:
Set vMaxDate = '=Date(Max(Date))';
Use in expression: =vMaxDate
Set vMinDate = 'Date(Min(Date))';
Use in expression ='$(vMinDate)' // quotes needed for a date