Operators in TI : SQL IN equivalent

Post Reply
Emixam
Posts: 139
Joined: Tue May 21, 2019 3:33 pm
OLAP Product: TM1
Version: PA 2.0.x
Excel Version: 2016
Location: The Internet

Operators in TI : SQL IN equivalent

Post by Emixam »

Hello,

What's the best way to do this SQL code in a TI ?

Code: Select all

WHERE nAmount > 0 AND sCode IN ('A', 'B', 'C')
I was thinking about something like this :

Code: Select all

IF(nAmount > 0 & (sCode @= 'A' % sCode @= 'B' % sCode @= 'C') );
	#Do Something
ENDIF;
But i'm not sure how TM1 handle the parenthesis.
This next code works but I wonder if there's a "better" way to do it ? Is there an equivalent of "IN" in TM1 ?

Code: Select all

IF(nAmount > 0);
	IF(sCode @= 'A' % sCode @= 'B' % sCode @= 'C');
		#Do Something
	ENDIF;
ENDIF;
Thanks and have a good day !
User avatar
PavoGa
MVP
Posts: 617
Joined: Thu Apr 18, 2013 6:59 pm
OLAP Product: TM1
Version: 10.2.2 FP7, PA2.0.9.1
Excel Version: 2013 PAW
Location: Charleston, Tennessee

Re: Operators in TI : SQL IN equivalent

Post by PavoGa »

SCAN(sCode, 'ABC') > 0
Ty
Cleveland, TN
Emixam
Posts: 139
Joined: Tue May 21, 2019 3:33 pm
OLAP Product: TM1
Version: PA 2.0.x
Excel Version: 2016
Location: The Internet

Re: Operators in TI : SQL IN equivalent

Post by Emixam »

I always neglect this function !!

You reversed the parameter ..

SCAN( sFindMe, sScanMe );

Code: Select all

IF(nAmount > 0 & SCAN( 'ABC', sCode ) > 0 );
	#Do Something
ENDIF;
Thanks Ty !

EDIT: Here's the correct code:

Code: Select all

IF(nAmount > 0 & SCAN( sCode, 'ABC' ) > 0 );
	#Do Something
ENDIF;
Last edited by Emixam on Thu Jun 27, 2019 5:20 pm, edited 1 time in total.
MarenC
Regular Participant
Posts: 349
Joined: Sat Jun 08, 2019 9:55 am
OLAP Product: Planning Analytics
Version: Planning Analytics 2.0
Excel Version: Excel 2016

Re: Operators in TI : SQL IN equivalent

Post by MarenC »

Hi,

am I being a bit slow here, but isn't the point to reverse the parameter? I.e. it should be SCAN(sCode, 'ABC') > 0.

Scan('ABC', sCode) does not make much sense to me?

regards, Maren
Wim Gielis
MVP
Posts: 3113
Joined: Mon Dec 29, 2008 6:26 pm
OLAP Product: TM1, Jedox
Version: PAL 2.0.9.18
Excel Version: Microsoft 365
Location: Brussels, Belgium
Contact:

Re: Operators in TI : SQL IN equivalent

Post by Wim Gielis »

You’re right Maren
Best regards,

Wim Gielis

IBM Champion 2024
Excel Most Valuable Professional, 2011-2014
https://www.wimgielis.com ==> 121 TM1 articles and a lot of custom code
Newest blog article: Deleting elements quickly
Emixam
Posts: 139
Joined: Tue May 21, 2019 3:33 pm
OLAP Product: TM1
Version: PA 2.0.x
Excel Version: 2016
Location: The Internet

Re: Operators in TI : SQL IN equivalent

Post by Emixam »

You are right !! I really need to sleep!

Thanks guys !
Andy Key
MVP
Posts: 351
Joined: Wed May 14, 2008 1:37 pm
OLAP Product: TM1
Version: 2.5 to PA
Excel Version: Lots
Location: Sydney
Contact:

Re: Operators in TI : SQL IN equivalent

Post by Andy Key »

As string comparison is not case sensitive ('b'='B'), but Scan is (Scan( 'b', 'B') = 0); and as you are matching on a specific term not a combination of terms (i.e. sCode = 'B' should pass but sCode = 'BC' should fail) I would go with:

Code: Select all

If( Scan( '<' | Upper( sCode) | '>', '<A><B><C>') > 0)
Include an Upper round the second part of the Scan if necessary.
Andy Key
User avatar
PavoGa
MVP
Posts: 617
Joined: Thu Apr 18, 2013 6:59 pm
OLAP Product: TM1
Version: 10.2.2 FP7, PA2.0.9.1
Excel Version: 2013 PAW
Location: Charleston, Tennessee

Re: Operators in TI : SQL IN equivalent

Post by PavoGa »

Andy Key wrote: Fri Jun 28, 2019 4:14 am As string comparison is not case sensitive ('b'='B'), but Scan is (Scan( 'b', 'B') = 0); and as you are matching on a specific term not a combination of terms (i.e. sCode = 'B' should pass but sCode = 'BC' should fail) I would go with:

Code: Select all

If( Scan( '<' | Upper( sCode) | '>', '<A><B><C>') > 0)
Include an Upper round the second part of the Scan if necessary.
There are a number of ways to manage this depending on overall context of the TI or rule. This:

Code: Select all

If( Scan( EXPAND('<%sCode%>'), '<A><B><C>') > 0);
Of course this does not deal with the fact that the <A><B><C> string has to be built if dynamic. And if the assumption is that sCode must be a single char then:

Code: Select all

If( Scan(UPPER(sCode), 'ABC') > 0 & LONG(sCode) = 1);
Ty
Cleveland, TN
Post Reply