How to do an IF EXISTS in hana SQL query

isambardtech picture isambardtech · May 16, 2017 · Viewed 11.2k times · Source

I have this query code:

IF EXISTS  ( 

SELECT 

 *

 FROM sys.objects

 WHERE object_id =
 OBJECT_ID(N'[dbo].[BAL_WMS_STAGING]') 

 AND type in (N'U')

)

 DROP TABLE
 [dbo].[BAL_WMS_STAGING] 

GO 
 CREATE TABLE

I am trying to use this statement to query an SAP Hana Database. The beginning of the query IF EXISTS keeps throwing an error, I assume that this means that this keyword does not exist in Hana SQL syntax. Does anyone know how to do an IF EXISTS check in Hana, as I am unable to find any answer online.

Answer

Lars Br. picture Lars Br. · May 17, 2017

If EXISTS is a non-standard syntax that HANA doesn't support. As an alternative you can query the catalog and write a IF...THEN statement in SQLScript.