From: Rob Sargent <robjsargent@gmail.com>
To: Łukasz Jarych <jaryszek@gmail.com>
Cc: pgsql-general@postgresql.org <pgsql-general@postgresql.org>
Subject: Re: Run Stored procedure - function from VBA
Date: Tue, 19 Jun 2018 13:54:15 -0600
Message-ID: <40a7adef-672b-a311-1f36-e7b3dc6ab063@gmail.com> (raw)
In-Reply-To: <CAGv31oe70OFeENRj--2YUqWATXtiHGX7ie=o+WDX4tepzcTPNw@mail.gmail.com>
References: <CAGv31odanrcg7zZ3K3jUPOp8kHydvvbO5-rQOxRTNUiwVOpZ-g@mail.gmail.com>
<0FB3637B-95EC-453A-8458-5A1ED525850E@gmail.com>
<CAGv31oe70OFeENRj--2YUqWATXtiHGX7ie=o+WDX4tepzcTPNw@mail.gmail.com>
On 06/18/2018 09:51 PM, Łukasz Jarych wrote:
> Thank you Rob,
>
> question is it is the optimal way to run SP from VBA?
> Or not?
>
> Best,
> Jacek
>
> 2018-06-19 1:34 GMT+02:00 Rob Sargent <robjsargent@gmail.com
> <mailto:robjsargent@gmail.com>>:
>
>
>
>> On Jun 18, 2018, at 9:47 AM, Łukasz Jarych <jaryszek@gmail.com
>> <mailto:jaryszek@gmail.com>> wrote:
>>
>> Hi Guys,
>>
>> i have example function :
>>
>> CREATE OR REPLACE FUNCTION totalRecords ()
>> RETURNS integer AS $total$
>> declare
>> total integer;
>> BEGIN
>> SELECT count(*) into total FROM COMPANY;
>> RETURN total;
>> END;
>> $total$ LANGUAGE plpgsql;
>>
>> and i want to run it from VBA using odbc connection.
>>
>> What is the best way to use it ?
>>
>> something like this:
>>
>> |Dim dbCon asnew ADODB.Connection Dim rst asnew ADODB.Recordset
>> Dbcon.connectionstring=”Your connection string goes
>> here!”Dbcon.openRst.openstrsql|
>> where strsql is "Select * from totalRecords" or this is not a
>> good solution?
>>
>> Best,
>> Jacek
>
> You need the parentheses after the function name: “select * from
> totalrecords();"
>
>
Depends on the usage pattern. I'm sure there is an ODBC construct for
stored procedures/function, which you could build once and re-use with
new parameter values if you're going to call this repeatedly.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: robjsargent@gmail.com, jaryszek@gmail.com
Subject: Re: Run Stored procedure - function from VBA
In-Reply-To: <40a7adef-672b-a311-1f36-e7b3dc6ab063@gmail.com>
References: <CAGv31odanrcg7zZ3K3jUPOp8kHydvvbO5-rQOxRTNUiwVOpZ-g@mail.gmail.com> <0FB3637B-95EC-453A-8458-5A1ED525850E@gmail.com> <CAGv31oe70OFeENRj--2YUqWATXtiHGX7ie=o+WDX4tepzcTPNw@mail.gmail.com> <40a7adef-672b-a311-1f36-e7b3dc6ab063@gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox