Solved

Query string concatenation in Access SQL

Posted on 2009-04-06
2
1,262 Views
Last Modified: 2013-11-27
I wish to concatenate two or more SQL queries on an Access database, eg in the Code snippet

I can do this on a SQL Server database but Access does not like it.  It doesnt like me using semi-colon separators either.

 How can I make it work in Access?

sSQL = " DECLARE @oldMaxItemID int " _
 
                & " SET @oldMaxItemID = ( SELECT MAX(ItemID) " _
 
                & " FROM Controls ) " _
 
                & " " _
 
                & " INSERT INTO Controls " _
 
                & " SELECT ApplicationName, FormName, ParentName, " _
 
                & " ControlName, ControlType, ControlText, ControlBackColour, ControlForeColour, " _
 
                & " LanguageCode, TranslatedControlText " _
 
                & " FROM Controls " _
 
                & " WHERE LanguageCode = '" & AUST_ENGLISH_LANGUAGE_CODE & "' " _
 
                & " AND ApplicationName = '" & anApplicationName & "'  "
 
 
 
            sSQL = sSQL & " UPDATE Controls " _
 
                & " SET LanguageCode = '" & aLanguageCode & "' " _
 
                & " WHERE ItemID > @oldMaxItemID "
 
 
 
            sSQL = sSQL & " DECLARE @oldMaxMessageID int " _
 
                & " SET @oldMaxMessageID = ( SELECT MAX(MessageID) " _
 
                & " FROM Message ) " _
 
                & " " _
 
                & " INSERT INTO Message " _
 
                & " SELECT ApplicationName, Message, " _
 
                & " LanguageCode, [Translation] " _
 
                & " FROM Message " _
 
                & " WHERE LanguageCode = '" & AUST_ENGLISH_LANGUAGE_CODE & "' " _
 
                & " AND ApplicationName = '" & anApplicationName & "'  "
 
 
 
            sSQL = sSQL & " UPDATE Message " _
 
                & " SET LanguageCode = '" & aLanguageCode & "' " _
 
                & " WHERE MessageID > @oldMaxMessageID "

Open in new window

0
Comment
Question by:edwardr
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 74

Accepted Solution

by:
Jeffrey Coachman earned 500 total points
ID: 24083713
You cannot concatenate SQL queries in Access.

You must run them one at a time indivudually:

Something like this:

CurrentDB.Execute "Select...", dbFailonError
CurrentDB.Execute "Delete...", dbFailonError
CurrentDB.Execute "Insert...", dbFailonError

JeffCoachman

0
 

Author Closing Comment

by:edwardr
ID: 31567318
That works.
Thanks.
EdwardR
0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question