Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fV3ip-0007up-4i for pgsql-general@arkaria.postgresql.org; Mon, 18 Jun 2018 23:38:07 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fV3io-0004ga-7I for pgsql-general@arkaria.postgresql.org; Mon, 18 Jun 2018 23:38:06 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fV3f0-0006jX-2T for pgsql-general@lists.postgresql.org; Mon, 18 Jun 2018 23:34:10 +0000 Received: from mail-pl0-x241.google.com ([2607:f8b0:400e:c01::241]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1fV3ew-00084I-Lf for pgsql-general@postgresql.org; Mon, 18 Jun 2018 23:34:08 +0000 Received: by mail-pl0-x241.google.com with SMTP id g20-v6so9884841plq.1 for ; Mon, 18 Jun 2018 16:34:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:message-id:mime-version:subject:date:in-reply-to:cc:to :references; bh=5x7eINYhVDmCWpHrUbojjN7SCNGql7G/Bu8dKq5Jg/U=; b=Np3jSlITgW6z7UtoxBSakbtxcsCyEgMWnhpxor0vvD8ndGBByd1m5otYhcTYMf76hd N8z2H58iX92HTRb7b9loApuRBZ8XN5SseUOxYMX8zRtVnHvM5vOq6I/dcqEtChTz3YVR eNaqEXwR15ioCRso4t3ZN085DhyTmFWjTOrfusn4fCFqvNK0NSk+fxdFLEd6IChPFNqc lbK+ribmp5f/ZSc6XY0KRoSqKgGMeJDzLP1kPgdlmXvT8nAeA3d0ntTWyKeUksDBwTpH VwH7mgZ/KN+6jc4SmQ4tj1bKhVWAgo4A6BkSzFlIVGCdXPFzYwK6YPGY5GedFkpu8oBn 1+Bg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:message-id:mime-version:subject:date :in-reply-to:cc:to:references; bh=5x7eINYhVDmCWpHrUbojjN7SCNGql7G/Bu8dKq5Jg/U=; b=DhJNNnYBX2hPpXOWQOG4Nh1ioXsjhTg5W8x7C/TIcBNzU76DbbLC+lGGSXYMFf4/pY aXRtFs5yG6oIoLy/h+p+MnyfEjmh1t3zCCB84b5IWAHamsHPeH2aEME1u5iQXmPwqySd iF14Ezi87wsEJLs1Aip+zhOSQdyPw+bT4XuZwVrLGEfPnf+lDCFulVw1Abfn9Pk0Tm/4 1l6GgGE2Dj59YMV2bJgSWSM2As36j4r6VhVEUEM0UE+Wo6sJoKL+9GOX3U3zvpWqxgpx LYrybi5qNxTiZGePzoIKhIZe2B4L0peNSGoGOHDgc6H+5x6fi6qjzTiM5+Joh+Sd2Oat 1wTw== X-Gm-Message-State: APt69E0Oiw6Hq9dViN8dhnkCQLC4K2L2Nz5sB+TloRxjWF3tVvnILfrc A58zIBZmR/r5wQJOO7bhWY8= X-Google-Smtp-Source: ADUXVKLFUXLieA8dnz22W1zb48wTBEVkRlAnV7yMpZxKYu767Xv8LImZ4YewvjIDTbykZwhX3ymBRw== X-Received: by 2002:a17:902:7686:: with SMTP id m6-v6mr16334580pll.340.1529364845587; Mon, 18 Jun 2018 16:34:05 -0700 (PDT) Received: from kitselas.hci.utah.edu ([155.100.47.2]) by smtp.gmail.com with ESMTPSA id r26-v6sm39055293pfj.180.2018.06.18.16.34.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 18 Jun 2018 16:34:04 -0700 (PDT) From: Rob Sargent Message-Id: <0FB3637B-95EC-453A-8458-5A1ED525850E@gmail.com> Content-Type: multipart/alternative; boundary="Apple-Mail=_EB66B520-7445-4EFB-B5A5-E1343367A8C1" Mime-Version: 1.0 (Mac OS X Mail 11.3 \(3445.6.18\)) Subject: Re: Run Stored procedure - function from VBA Date: Mon, 18 Jun 2018 17:34:04 -0600 In-Reply-To: Cc: "pgsql-general@postgresql.org" To: =?utf-8?Q?=C5=81ukasz_Jarych?= References: X-Mailer: Apple Mail (2.3445.6.18) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --Apple-Mail=_EB66B520-7445-4EFB-B5A5-E1343367A8C1 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On Jun 18, 2018, at 9:47 AM, =C5=81ukasz Jarych = wrote: >=20 > Hi Guys, >=20 > i have example function : >=20 > 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; >=20 > and i want to run it from VBA using odbc connection.=20 >=20 > What is the best way to use it ? >=20 > something like this:=20 >=20 > Dim dbCon as new ADODB.Connection > Dim rst as new ADODB.Recordset >=20 > Dbcon.connectionstring=3D=E2=80=9DYour connection string goes here!=E2=80= =9D > Dbcon.open >=20 > Rst.open strsql > where strsql is "Select * from totalRecords" or this is not a good = solution? >=20 > Best, > Jacek You need the parentheses after the function name: =E2=80=9Cselect * from = totalrecords();" --Apple-Mail=_EB66B520-7445-4EFB-B5A5-E1343367A8C1 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8

On Jun 18, 2018, at 9:47 AM, =C5=81ukasz Jarych <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 as new ADODB.Connection
Dim rst as new ADODB.Recordset

Dbcon.connectionstring=3D=E2=80=9DYour connection string goes here!=E2=80=9D
Dbcon.open

Rst.open strsql
where strsql is "Select * from totalRecords" or = this is not a good solution?

Best,
Jacek

You need the parentheses = after the function name: =E2=80=9Cselect * from = totalrecords();"

= --Apple-Mail=_EB66B520-7445-4EFB-B5A5-E1343367A8C1--