Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do an IF EXISTS in hana SQL query

Tags:

sql

hana

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.

like image 743
isambardtech Avatar asked Oct 18 '22 12:10

isambardtech


1 Answers

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.

like image 110
Lars Br. Avatar answered Oct 21 '22 01:10

Lars Br.