Qlik Community

QlikView Creating Analytics

Discussion Board for collaboration related to Creating Analytics for QlikView.

kunkumnaveen
Contributor III

how to write if statement

Hello All,

I really have no clue whether the thing i am looking is possible  in qlikview or not

the thing is ,currently i moved my application from quality server to production and the issuse is a table which is existing in quality server will be exist in production server after a while i mean in a two months,

so what i am looking is i need to write a code in a way so that it should check if the table is existing in server then load the table in to qvd if not skip that without throwing error and without  halting the script run......is it possible

coal:

SELECT * from ZCOAL_FINAL_DASH;

  STORE coal into $(vPath)Coal.qvd(qvd);

DROP Table coal;

6 Replies
manucamon
Valued Contributor III

Re: how to write if statement

Hi Naveen,

You can use NoOfRows, if there isn't any row you will not load this table:

coal:

LOAD *;

SELECT * from ZCOAL_FINAL_DASH;

IF NoOfWors('coal')>0 THEN

  STORE coal into $(vPath)Coal.qvd(qvd);

  DROP Table coal;

END IF;

kunkumnaveen
Contributor III

Re: how to write if statement

still getting same error

screen.png

amartinez35
Valued Contributor

Re: how to write if statement

Hi,

For check if table exists :

For SQL Server

SELECT 1
  
FROM INFORMATION_SCHEMA.TABLES
  
WHERE TABLE_TYPE='BASE TABLE'
  
AND TABLE_NAME='mytablename'


For oracle

select count(*) into c from user_tables where table_name = upper('table_name');


and after use the Manuel solution.


Aurélien

sasiparupudi1
Honored Contributor III

Re: how to write if statement

It looks like an sql error rather than a qlikview error..

May be you are missing the scehma prefix in you select statement in qlik

SELECT * from [dbo].ZCOAL_FINAL_DASH;

hth

Sasi

sasiparupudi1
Honored Contributor III

Re: how to write if statement

Hi

Sorry, I misunderstood your question. Please ignore my above comment

set ErrorMode=0;  //to suppress the message box

if (ScriptError=2) or (ScriptError=10) then   ///2 general error 10 table not found

STORE coal into $(vPath)Coal.qvd(qvd);

DROP Table coal;

end if;

hth

Sasi

manucamon
Valued Contributor III

Re: how to write if statement

Hi Naveen:

TableExists:

//Here search on Objects of data base if your table exists on server

IF NoOfWors('TableExists')>0 THEN

     coal:

     LOAD *;

     SELECT * from ZCOAL_FINAL_DASH;

  STORE coal into $(vPath)Coal.qvd(qvd);

  DROP Table coal;

END IF;

Community Browser