Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Using SQL Statement stored in another table

Hi,

I want to load a SQL which is stored in a column called statement of another Table.

The output from all SQL statements in the table needs to be concatenated.

I am using the following code

[ code ]

ODBC CONNECT TO XXXXX;


[SQLCODE]:
LOAD `sqlcode`,
statement,
title,
description,
dropoffpct,
avgsettlevalue,
avgpctcomp;
SQL SELECT *
FROM misql;

LET vLoop=noofrows('SQLCODE');


FOR i = 0 to $(vLoop)-1
LET vSQL = peek('statement',$(i),SQLCODE);
SQL $(vSQL);
NEXT i

[ /code ]

---------------------------------------
Error Msg
---------------------------------------
ODBC read failed
SQL SELECT *
FROM midata d, mirejections r
WHERE d.archstatus = 'Live'
AND d.rejectedreasons = r.type
AND d.claimtypedesc LIKE '%fast track%'
AND d.dmclaimtypedesc LIKE '%car accident%'
AND r.wipinc = '1'
AND d.feeearnerdesc NOT
IN (
'Allocation Manager PI', 'Allocation Manager SM'
)
AND d.feteamname NOT
IN (
'Assessment Team', 'Hera'
)
ORDER BY d.fileopened DESC
---------------------------------------

What could be going wrong?

Any help is greatly appreciated!!

3 Replies
Not applicable
Author

It would help to see what is in vSQL when it fails.

I'm guessing that when you are passing through the SQL - you have a SQL SQL Select going.

Not applicable
Author


wshpuntoff wrote:

It would help to see what is in vSQL when it fails.

I'm guessing that when you are passing through the SQL - you have a SQL SQL Select going.
<div></div>



Thanks... but it seems issue is with the SQL. (the one given in ERROR message.

when I run that statement directly in MySQL it s running fine. I tried running it Directly in Script, still it gves the same error in Qlikview.

Other simple queries are running fine.

Anonymous
Not applicable
Author

Hi,

Does this part run?

SQL SELECT *
FROM midata d, mirejections r

I'm thinking the problem might be the column names here. Try encapsulating them in " " or [ ], "midata d" for example.