Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in Bucharest on Sept 18th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
surajap123
Creator III
Creator III

storing as string

Hi Experts,

I wanted to store the below part of the expression in a variable-

FIELD={Gross Sales}

I see that it is written like below

LET vGrossSales = 'FIELD={'&Chr(39) & 'Gross Sales' &Chr(39) & '}';

But not like-

LET vGrossSales = 'FIELD={Gross Sales}';

why??

Also, Why we need chr(39) when 'gross sales' already has single cotes?

1 Solution

Accepted Solutions
rubenmarin

Hi Suraj, you want your expression result as:

sum({<FIELD={Gross Sales}>}sales)

or:

sum({<FIELD={'Gross Sales'}>}sales)

I think it's the second so to add the single quotes you need to add the Chr(39).

At the end of your first post you said "Also, Why we need chr(39) when 'gross sales' already has single cotes?", I tried to clarify that the result expression wouldn't have single quotes if you avoid the Chr(39), other single quotes in that expression only delimiters strings.

LET vGrossSales = 'FIELD={'&Chr(39) & 'Gross Sales' &Chr(39) & '}';


You can check the result without the Chr(39):

LET vGrossSales = 'FIELD={'& 'Gross Sales' & '}';

View solution in original post

7 Replies
Not applicable

There is no escape characters in qlikview. so we need to use chr() for quotes.

Anonymous
Not applicable

Using

     LET vGrossSales = 'FIELD={Gross Sales}';


should work fine.


Do you have reason to suspect it does not ?

rubenmarin

Hi Suraj, in this expression:

LET vGrossSales = 'FIELD={'&Chr(39) & 'Gross Sales' &Chr(39) & '}';


The bolded parts will be the result of the expression, so "Gross Sales" isn't between single quotes in the result, so you need to add the quotes using CHR(39).


Another way is to use double-single quotes as scape character but can be more confusing than using Chr():

LET vGrossSales = 'FIELD={''Gross Sales''}';

surajap123
Creator III
Creator III
Author

Sorry, i didnt clearly understand what you said, could you please explain this statement..

The bolded parts will be the result of the expression, so "Gross Sales" isn't between single quotes in the result--

For more infomation, I will be using the above varaible in my expression like below-

sum({<$(vGrossSales)>}sales)

rubenmarin

Hi Suraj, you want your expression result as:

sum({<FIELD={Gross Sales}>}sales)

or:

sum({<FIELD={'Gross Sales'}>}sales)

I think it's the second so to add the single quotes you need to add the Chr(39).

At the end of your first post you said "Also, Why we need chr(39) when 'gross sales' already has single cotes?", I tried to clarify that the result expression wouldn't have single quotes if you avoid the Chr(39), other single quotes in that expression only delimiters strings.

LET vGrossSales = 'FIELD={'&Chr(39) & 'Gross Sales' &Chr(39) & '}';


You can check the result without the Chr(39):

LET vGrossSales = 'FIELD={'& 'Gross Sales' & '}';

jonathandienst
Partner - Champion III
Partner - Champion III

There is no escape characters in qlikview. so we need to use chr() for quotes.

That is no longer true - at least from 11.2 SR9. You can escape a single quote by entering it twice:

Set vGrossSales = 'FIELD={''Gross Sales''}';

this results in

FIELD={'Gross Sales'}

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
surajap123
Creator III
Creator III
Author

Hi Martin,

Thanks a lot for the explantion and clarification