Skip to main content
Announcements
Global Transformation Awards! Applications are now open. Submit Entry
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Load Script - if statement with string concatenation

Hi all,

I am having problems to have string concatenation in an if statement in a load script SQL statement.

Example:

SQL

Select IF(Month(`TxDate`) < 8, 'Season ' + Year(`TxDate`), 'Season ' + (Year(`TxDate`)+1)) AS Season

Can anyone explain what I am doing wrong?

5 Replies
antoniotiman
Master III
Master III

Hi Colin,

If() not is sintax SQL, is sintax QV.

You use

case
When ...   then

else ..

end

as Season.

But Month Sintax depending on Your DB.

You can use Preceding Load :

Load *,

If(Month(...),........) as Season;

SQL Select *

from Table;

Regards,

Antonio

Not applicable
Author

Hi Antonio,

Thanks for your reply.

However the If statement is not the issue as it is working fine. It is the concatenation which is working not as expected.

This expression:

('Season ' & (Year(`TxDate`)-1) & '-' & (Year(`TxDate`))

is resulting in 0.


I am sure that Year works fine as I tried it as a separate expression. I am afraid that & is being interpreted as a logical AND expression.


Btw - I am using MySQL but this is not the issue.


Thanks,

Colin

antoniotiman
Master III
Master III

Colin,

Ok, MySql has If() Sintax.

Tray to remove ' in Year('TxDate')  -> Year(TxDate)

Anonymous
Not applicable
Author

Hi

Just to be sure, try replacing the &'-'& with &'_'& or some other separator.

Not applicable
Author

I solved this issue with a preceding load as follows:

LOAD      *,

               IF(Month(`TxDate`) < 8, 'Season ' + Year(`TxDate`), 'Season ' + (Year(`TxDate`)+1)) AS Season;

SQL

Select      TxDate

From ...