Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Inserting field with an if statement

Hi everyone,

I have imported a few SQL database tables into my qlikview worksheet, but I am interested in creating a new field on this import and can't seem to get it to work.

This is what the non-working code looks like:

TableName:

SQL SELECT

"Field1",

"Field2",

if(Field1 < 30, 'current'),

if(Field1 > 29 AND Field 1 <60, '30-59'),

if(Field1 > 59 AND Field1 < 90, '60-89'),

if(Field1 > 89 AND Field1 <120, '90-119'),

if(Field1 > 119, '120+') as [Description]


FROM SQL table name;


If you can't tell from the code I am trying to use logic based on field1 to insert specific strings into a new field called Description. Does anyone know what I am doing wrong?


Thank you

11 Replies
Not applicable
Author

Hi Mathew,

you can also use like this

TableName:

SQL SELECT

*

FROM SQL table name;


Final:

load

"Field1",

"Field2",

if(Field1 < 30, 'current'),

if(Field1 > 29 AND Field 1 <60, '30-59'),

if(Field1 > 59 AND Field1 < 90, '60-89'),

if(Field1 > 89 AND Field1 <120, '90-119'),

if(Field1 > 119, '120+') as [Description]

Resident TableName;

drop table TableName;

Hope this help 🙂

Regards

Deepak

maxgro
MVP
MVP

I think after SQL SELECT

you can use the syntax of the database, not the syntax of qlikview

does your database support if .... ?

if you want to use Qlikview syntax use

Table:

// start Qlik

LOAD

     *,

     if................ as ........

     ;

// end Qlik

// start db

SQL

     SELECT

     SQL SELECT

     "Field1",

     "Field2"

     FROM SQL table name;