I would like to use if-else statement to decide at what location I have to export data. My case is:
- I extract several files from the azure blob storage (it's possible that there are no files!!).
- I calculate count of records in file set.
- If count of records is > 20 then I export files into specific report location
- If in file set are no records, I have to output dummy empty file into different location, because I don't want replace existing report by empty report.
The solution may be IF..ELSE confition. The problem is that if I calculate count of records I got rowset variable and I cannot compare it with scalar variable.
@RECORDS =
SELECT COUNT(id) AS IdsCount
FROM @final;
IF @RECORDS <= 20 THEN //generate dummy empty file
OUTPUT @final_result
TO @EMPTY_OUTPUT_FILE
USING Outputters.Text(delimiter : '\t', quoting : true, encoding : Encoding.UTF8, outputHeader : true, dateTimeFormat : "s", nullEscape : "NULL");
ELSE
OUTPUT @final_result
TO @OUTPUT_FILE
USING Outputters.Text(delimiter : '\t', quoting : true, encoding : Encoding.UTF8, outputHeader : true, dateTimeFormat : "s", nullEscape : "NULL");
END;