Not sure if this is helpful, but I have created several procs that I use when connecting to MSSQL, which I do for a good portion of my applications.

Here is an example of one.

This is a proc called getremotefulltable.
param tablename, cursorname


gnConnHandle =sqlconnect("matchbackODBC","servicename","service pwd")
lianja.writelog(str(gnConnHandle))
strw1 =' select * from '+tablename+' '
=SQLPREPARE(gnConnHandle,strw1,'cresult')
=SQLEXEC(gnConnHandle)
macro = 'select * from cresult into cursor '+cursorname+' readwrite'
&macro
use in cresult
=sqldisconnect(gnConnHandle)
I use it like this.

getremotefulltable('exceptions','c_exceptions')

So then in Lianja, I have a cursor called c_exceptions which exists after the connection string is closed.

I the same thing for filtered tables where I also pass in a where condition.

Just my 2 cents.

Herb