Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
jblomqvist
Specialist
Specialist

How can I write an If statement for a Drop Field statement like this?

Hi all,

I am trying to write a query like below:

TableA:

LOAD

floor(RAND()*17)+10 as Test,

1 as Counter

AutoGenerate 23;

If($(vDropField)=1, Drop Field Counter, False);

Basically I want to drop the field is the vDropField variable contains 1, else don't drop the field.

It doesn't work when I write it. Any idea how to do this please?

31 Replies
jblomqvist
Specialist
Specialist
Author

Hi Sunny,

I seem to have solved it.

Strange behaviour initially, I had an InputBox with the variable value but it gave me the above error.

So then I went to Variable Overview and assigned a 1 to the variable and reloaded. And it ran fine and dropped the field.

sunny_talwar

That is strange, I would have expected inputbox to have worked the same way as variable view. Are you sure you were using the right variable in the inputbox? Can you check making changes to the value (may be assign 2) through the input box and see if that changes the value in variable overview? Trying to understand where the disconnect is.

swuehl
MVP
MVP

And have you actually confirmed the input value in your input box by either clicking another object or pressing Enter before starting the reload?

jagan
Luminary Alumni
Luminary Alumni

Hi,

Try like this

LET vDropField = 1;  //or replace with your expression

TableA:

LOAD Floor(Rand() * 17) + 10 as Test,

          1 as Counter

AutoGenerate 23;

If vDropField = 1 then

     DROP Field Counter;

ENDIF

sunny_talwar

Seems to be working in the attached file

jblomqvist
Specialist
Specialist
Author

Hi guys,

What I want to do is get the script to load the Counter field if vDropField does not evaluate to 1.

So far this code works if it evaluates to 1:

TableA:

LOAD

floor(RAND()*17)+10 as Test,

1 as Counter

AutoGenerate 23;

If $(vDropField) = 1 then

     DROP Field Counter;

ENDIF

How can I put an ELSE in to load the Counter field if vDropField does not evaluate to 1?

In essence what I am trying to do is allow the user to say load the field or not.

swuehl
MVP
MVP

Let vCounterLoad = If( $(vDropField) = 1,'',', 1 as Counter');

TableA:

LOAD

floor(RAND()*17)+10 as Test

$(vCounterLoad)

AutoGenerate 23;

sunny_talwar

May be this:

TableA:

LOAD

floor(RAND()*17)+10 as Test,

1 as Counter

AutoGenerate 23;

If $(vDropField) <> 1 then

     DROP Field Counter;

ENDIF

Kushal_Chawda

another solution

TableA:

LOAD

floor(RAND()*17)+10 as Test,

1 as Counter

AutoGenerate 23;

If $(vDropField) = 1 then

    DROP Field Counter;

ELSE

Drop table TableA;

TableA:

LOAD

floor(RAND()*17)+10 as Test,

1 as Counter

AutoGenerate 23;

ENDIF

jagan
Luminary Alumni
Luminary Alumni

Hi,

Try like this for else

TableA:

LOAD

floor(RAND()*17)+10 as Test,

1 as Counter

AutoGenerate 23;

If $(vDropField) = 1 then

     DROP Field Counter;

ELSE

     // Else statements goes here

ENDIF