Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
I have a report that I am using to building a QVD. Sometimes the field comes in as [field name] other times it will come in as [Field Name] is there a way to use an if statement in the load script. A lot of the fields require wrapping and formatting so I am unable to just use the * to bring everything in.
If(Exists([field name]),[field name],[Field Name]) as NewName,
I am currently using the Set ErrorMode in an If statement, but this is making my script rather large and cumbersome, I am hoping that there is an easier was to do it within the line rather than having to double up on the entire load script
A workaround is to use the ALIAS function. As you don't know which files contains [Field Name] and which contains [field name] you will need to load *. I would suggest something like this.
Alias [field name] as [Field Name];
TMP:
Load * from filepath\*.qvd;
Final:
NoConcatenate LOAD
[Field Name],
LEFT(field2) as etc...
RESIDENT TMP;
DROP TABLE TMP;
will the alias method work if the field doesn't exist? Since the field alternates between 'field name' and 'Field Name' I am trying to use:
Alias [field name] as [Name];
Alias [Field Name] as [Name];
But the problem I am running into is that only one of the field variants exist. It errors out once if gets to the one that doesn't exist
Yes it will work, but since you don't know which fields contains which field name you will need to use LOAD * in the initial load from the file. The Alias is done right after reading the file.
Alias [Field Name] as Name;
Alias [field name] as Name;
LoadStar:
LOAD
* //You can not use the field name Name explicit yet as the alias is done post loading data.
FROM [Files\that\contains\either\field name\or\Field Name\] ;
NoConcatenate LOAD
Name,
OtherField
Resident LoadStar;
Drop LoadStar;