Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

if statement when loading data from db

Hello all,

I'm new here and, already asking questions!

I have a requirement to create an incremental load script from a table which has about 6,5kk entries, which I kind of succeeded at(I think), but another requirement is to alter all adjustment quantity made in a certain type of location zone to be zero.

The attached script works fine, but when I try to insert an if statement to do so, it fails.

The if statement I've tried to write was:

if("Zone Code"]='ADJUST', '0',Quantity) as Quantity

If this is inserted anywhere within the load statement, the load fails.

What am I doing wrong in here? 🙂

Thanks for all help!

1 Solution

Accepted Solutions
Not applicable
Author

Okey try this rename the result of your if statement to following:

if( Upper( "Zone Code" ) = 'ADJUST', '0',Quantity) as Quantity2


if( Upper( [Zone Code] ) = 'ADJUST', '0',Quantity) as Quantity2 //Remember no space in ''

It looks like u have 2 fields with the same name, that cant be done in same load.

ex. will fail.

Quantity,

if( Upper( "Zone Code" ) = 'ADJUST', '0',Quantity) as Quantity

/Teis

View solution in original post

16 Replies
Not applicable
Author

Hi Robert,

Just the syntax on your fieldname, try the below

if([Zone Code]='ADJUST', '0',Quantity) as Quantity

hope that helps

Joe

maxgro
MVP
MVP

maybe

if([Zone Code]='ADJUST', 0, Quantity) as  Quantity

Not applicable
Author

I've inserted it as follows within the LOAD statement:

Untitled2.png

This is what I get when trying to reload or debug the script

Untitled.png

I am pretty sure this is some dumb typo on my account, please could you help me?

Is there anything extra I could send your way to make it easier to pinpoint?

Thanks!

Not applicable
Author

Same issue as in my reply to Joe above

Thanks!

Not applicable
Author

Hi Robert

it does not look like your having problem with the if statement, but a problem with your OLEDB SQL.

Can u try post the full SQL string?

/Teis

Not applicable
Author

This is embarrassing, but I need to ask, what exactly do you mean by full sql string [edit!]?

Please find the script in it's current state attached to this post!

Thanks,

buzzy996
Master II
Master II

in ur if statement their is a problem.

if("Zone Code"='ADJUST', '0',Quantity) as Quantity or

if([Zone Code]='ADJUST', '0',Quantity) as Quantity

Not applicable
Author

This correction was suggested by Joe Simmons - the script still fails saying OLEDB read failed, there is a screenshot above

Thanks

buzzy996
Master II
Master II

might be case sensitive issue,

If([Zone Code]='Adjust','0','Siva') or

If([Zone Code]='adjust','0','Siva')


------------

If("Zone Code"='Adjust','0','Siva') or

If("Zone Code"='adjust','0','Siva')