Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Ken_Hardwick
Contributor III
Contributor III

How to do a where clause on two columns in data load

Hello,

I have a sales transaction table that I am loading into Qlik Sense that I need to apply two filters too. One is the year and second is the ledger code that the transactions are posted too.

Every row has a year and I only need this year's information but each row also has a GL code that the transaction is posted too and this is where I need to filter multiple options. This is code that I have tried:

FROM SysproCompanyA.dbo.ArTrnDetail
WHERE TransactionGlCode = '3000-001'
or TransactionGlCode = '3003-001'
or TransactionGlCode = '3004-001'
or TransactionGlCode = '3006-001'
or TransactionGlCode = '3007-001'
or TransactionGlCode = '3008-001'
or TransactionGlCode = '3009-001'
and GlYear = 2019;

If I use the where clause just for the GlYear it pulls in 395,000 rows. When I run the above script, it runs past this. I stopped at 700,000 rows as I knew it wasn't working correctly.

What am I doing wrong?

1 Solution

Accepted Solutions
sujayrpatil
Partner - Contributor III
Partner - Contributor III

Hi,

Can you try using the below code.

FROM SysproCompanyA.dbo.ArTrnDetail
WHERE GlYear = 2019 and (TransactionGlCode = '3000-001'
or TransactionGlCode = '3003-001'
or TransactionGlCode = '3004-001'
or TransactionGlCode = '3006-001'
or TransactionGlCode = '3007-001'
or TransactionGlCode = '3008-001'
or TransactionGlCode = '3009-001');

 

Regards,

Sujay

View solution in original post

4 Replies
sujayrpatil
Partner - Contributor III
Partner - Contributor III

Hi,

Can you try using the below code.

FROM SysproCompanyA.dbo.ArTrnDetail
WHERE GlYear = 2019 and (TransactionGlCode = '3000-001'
or TransactionGlCode = '3003-001'
or TransactionGlCode = '3004-001'
or TransactionGlCode = '3006-001'
or TransactionGlCode = '3007-001'
or TransactionGlCode = '3008-001'
or TransactionGlCode = '3009-001');

 

Regards,

Sujay

jonathandienst
Partner - Champion III
Partner - Champion III

The previous post is correct -- 'And'  is higher in the order of operations than 'Or', much like x is higher order than + in normal arithmetic. You need to wrap the 'Or statements in parentheses to ensure they are calculated first.

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
jonathandienst
Partner - Champion III
Partner - Champion III

Or simplify by saying:

FROM SysproCompanyA.dbo.ArTrnDetail
WHERE 
	GlYear = 2019 and 
	TransactionGlCode In (
		 '3000-001', 
		 '3003-001',
		 '3004-001',
		 '3006-001',
		 '3007-001',
		 '3008-001',
		 '3009-001'
	);
Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
Ken_Hardwick
Contributor III
Contributor III
Author

Thanks for all the replies and the solution. Very helpful and has got me up and running.