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: 
marcusbohman
Contributor II
Contributor II

Using variable in from clause, numeric constant not valid

Hi,

I am using a FOR EACH loop to get the same fields from different tables in a DB2 database.

_________

FOR EACH vCountry IN '1A','AT'

LOAD

FIELD1,

FIELD2,

FIELD3,

FIELD4

SQL SELECT FIELD1,

FIELD2,

FIELD3,

FIELD4

FROM $(vCountry)XXXXX.XXXX;

NEXT vCountry;

___________

'AT' runs just fine but '1A' raises "Numeric constant 1AXXXXX.XXXX is not valid" error. I don't understand why a variable with non-numerical characters can be interpreted as a number. Is there a way to force the variable to be a string? Or any other solution to make all elements in my list be treated as strings?

Kind Regards,

Marcus

4 Replies
Clever_Anjos
Employee
Employee

It´s a DB2 error message, no Qlik

marcusbohman
Contributor II
Contributor II
Author

Thank you cleveranjos‌. I recognise that the error comes from DB2 but I think that a change in my QV script could avoid it. It seems to pass 'AT' as string but '1A' as numerical. Would you know any way of passing '1A' as string as well?

Or do you mean that I am posting in the wrong forum?

/Marcus

Clever_Anjos
Employee
Employee

As long as I can see (maybe I wrong) that SQL below would return error even into your DB2 client

SELECT FIELD1,

FIELD2,

FIELD3,

FIELD4

FROM 1AXXXXX.XXXX;

tamilarasu
Champion
Champion

Hi Marcus,

I am not sure but try adding single quotes around the variable name like below,

FOR EACH vCountry IN '1A','AT'

LOAD

FIELD1,

FIELD2,

FIELD3,

FIELD4;

SQL SELECT FIELD1,

FIELD2,

FIELD3,

FIELD4

FROM '$(vCountry)'XXXXX.XXXX;

NEXT vCountry;