Managing and debugging SQL queries in MS Access

后端 未结 9 2261
既然无缘
既然无缘 2020-11-21 22:08

MS Access has limited capabilities to manage raw SQL queries: the editor is quite bad, no syntax highlighting, it reformats your raw SQL into a long string and you can\'t in

9条回答
  •  佛祖请我去吃肉
    2020-11-21 22:42

    Are you talking here about what MS-Access calls 'queries' and SQL call 'views' or about the 'MS-Access pass-through' queries which are SQL queries? Someone could get easily lost! My solution is the following

    1. free SQL Server Management Studio Express, where I will elaborate and test my queries
    2. a query table on the client side, with one field for the query name (id_Query) and another one (queryText, memo type) for the query itself.

    I then have a small function getSQLQuery in my VBA code to be used when I need to execute a query (either returning a recordset or not):

    Dim myQuery as string, _
        rsADO as ADODB.recorset
    
    rsADO = new ADODB.recordset
    myQuery = getSQLQuery(myId_Query)
    
    'if my query retunrs a recordset'
    set rsADO = myADOConnection.Execute myQuery
    'or, if no recordset is to be returned'
    myADOConnection.Execute myQuery
    

    For views, it is even possible to keep them on the server side and to refer to them from the client side

    set rsADO = myADOConnection.execute "dbo.myViewName"
    

提交回复
热议问题