Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi Community,
I have a quick question, which someone on here is bound to be able to answer.
I am currently attempting to set up a load condition within the script, which only attempts to load a specific field in from a CSV if the value of a variable is over a certain value.
Unfortunately, the logic does not seem to work. The line in question is something basic such as:
if('$(FEEDLEVEL)' > '3.1',[Job Number],'??') as JobNumber
Where FEEDLEVEL equals a decimal number.
The purpose of this condition is that we have a number of different feed levels. In some feeds, the field 'Job Number' will be present; and in some it won't be.
When I attempt to run a reload on the script with the above defined and the FEEDLEVEL variable set to '3.1', I get an error "Field not found - <Job Number>".
I have also tried the below, but the script still complains about not being able to find 'Job Number', even when the value of FEEDLEVEL is set to something like '2':
if(wildmatch('$(FEEDLEVEL)','1*','2*','3.1'),'??', [Job Number]) as JobNumber
Please can somebody help me on this. Hopefully I've explained things ok.
Thanks
Jacob
Right, for anyone out there that might wish to do something similar, the solution is very simple. Declare a new String variable for the desired field, which will be instantiated with either value based on the appropriate condition.
For example:
if '$(FEEDLEVEL)' > '3.1' then
set JobNumber = "[Job Number]";
else
set JobNumber = "'??'";
end if
LOAD ...
$(JobNumber) as JobNumber
FROM ...
Hi, Jacob,
why do you work with strings? It is better using numbers. If necessary you can use the function Num#() to interpret the numbers.
In Load-Statement:
If(FEEDLEVEL>3.1,[Job Numer],'??') As JobNumber
but if you want to load only some data use this:
Load [Job Number] As JobNumber,
...
From tablename.csv (...)
Where FEEDLEVEL>3.1;
Hi, Jacob
is [Job Number] part of your original table? I`m asking because after this you rename it to JobNumber
Maybe your syntax would be like this:
if('$(FEEDLEVEL)' > '3.1',JobNumber,'??') as JobNumber
And then you can apply Martina`s recommendation about number comparison
Rgds,
Erich
Hi Brenner and Erich. Thanks for your replies.
The reason that I used this syntax is that when declaring FEEDLEVEL as you suggest, the script interprets this as a field within the csv.
I have also tried using Num# as you suggest to convert the string to a number. This doesn't work either. This field needs to be loaded in conditionally within the main table load to elimate issues with indexing.
Erich, in answer to your question [Job Number] is a field within a csv, which can be present or not depending on the level of feed that we are using. If we are using a feed level where [Job Number] does not appear in the csv, we want to ignore it (i.e. populate that field with '??'); otherwise, we want it adding to the table.
[Job Number] is not loaded into a table prior to this.
Thanks again,
Jacob
Right, for anyone out there that might wish to do something similar, the solution is very simple. Declare a new String variable for the desired field, which will be instantiated with either value based on the appropriate condition.
For example:
if '$(FEEDLEVEL)' > '3.1' then
set JobNumber = "[Job Number]";
else
set JobNumber = "'??'";
end if
LOAD ...
$(JobNumber) as JobNumber
FROM ...
Hi,
Do we need to set this if condition before the load statement or inside the load statement