Click here to monitor SSC
SQLServerCentral is supported by Redgate
Log in  ::  Register  ::  Not logged in
Home       Members    Calendar    Who's On

Add to briefcase

Check if table exists on IBM As400 database using sql statement Expand / Collapse
Posted Monday, June 23, 2008 8:36 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, February 16, 2011 8:08 AM
Points: 1, Visits: 7
I'm trying to check if a table exist on my IBM As400 database.
I'm using to create an application, which runs sql statements and sends them via an ODBC connection to the AS400.
99% of my app works, but I want to be able to check if a table exist before running any SQL's.

I've seen some examples on the net and in the forums such as the following:

--===== If the test table already exists, drop it IF OBJECT_ID('TempDB..#mytable','U') IS NOT NULL DROP TABLE #mytable

However, I'm not sure if my OBJECT_ID is not set properly or IBM doesn't like some of the commands being sent to it.

For instance in my create table statement I do the following:

query = "CREATE TABLE " & tmptable _


Private Sub ODBC_SQL()
ODBC_DataAdapter = New Odbc.OdbcDataAdapter(ODBC_Command)
ODBC_DataAdapter.SelectCommand = New System.Data.Odbc.OdbcCommand(query, ODBC_connect)
ODBC_DataAdapter.Fill(DataSet, "Cama_tbl")
End Sub

My create table statement works fine, and if I add a "DROP" table statement it works too. However, I basically want to check if the table exist first before I create the table so I won't get any error messages.

Any help is appreciated.
Post #521859
Posted Monday, June 23, 2008 8:58 AM



Group: General Forum Members
Last Login: Tuesday, November 29, 2016 8:05 AM
Points: 434, Visits: 599
Sorry dude, this is not an IBM forum. I would suggest trying one of those. You may have better luck.

Watch my free SQL Server Tutorials at:
Blog Author of:
DBA Rant –

Minion Maintenance is FREE:

Post #521883
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse