Multiple SQL Statements in MS Access

It was a new revelation to me that I couldn't use multiple SQL statements in a single query in an MS Access database. According to this quote from a Microsoft MVP:

Access versions starting with 2000 include MSDE as an alternative to Jet, which is where you can create Stored Procedures. Although earlier versions of Access do not include MSDE, you can still use ODBC to operate with MSDE through Access with a "Pass Thru Query" No matter which version of Access you write, you cannot place multiple SQL statements in a query if it is using Jet. No matter which version of Access you write, you can place multiple SQL statements in a query using MSDE (or SQL Server). You can put several queries in a Macro and execute the Macro as an alternative.

I wasn't particularly fond of the macro option, so I decided to write a quick fix using ADO.NET. IT went something like this: sql = "my sql statement 1;my sql statment 2;"
sqls = sql.split(";")
For i As Integer = 0 To sqls.Length - 2
   Me.ProgressBar1.Value = i / count * 100
   cmd.CommandText = sqls(i)
   cmd.ExecuteNonQuery()
Next
This was just a quick fix, but hope it helps someone out there.

Comments (1)

It's a very nice ideea. Neat and simple. Thanks !

jules Avatar jules | 27th Apr 2010

Leave a Comment

Your Comment