Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Problem parameterizing SQL window fuction

Received: by 10.100.84.17 with SMTP id h17mr3970529anb.24.1311105777212;
        Tue, 19 Jul 2011 13:02:57 -0700 (PDT)
X-BeenThere: pyodbc@googlegroups.com
Received: by 10.91.159.16 with SMTP id l16ls828347ago.5.gmail; Tue, 19 Jul
 2011 13:02:56 -0700 (PDT)
MIME-Version: 1.0
Received: by 10.91.45.17 with SMTP id x17mr998782agj.27.1311105776268; Tue, 19
 Jul 2011 13:02:56 -0700 (PDT)
Received: by y16g2000yqk.googlegroups.com with HTTP; Tue, 19 Jul 2011 13:02:56
 -0700 (PDT)
Date: Tue, 19 Jul 2011 13:02:56 -0700 (PDT)
In-Reply-To: <1f3174fa-fae3-42b6-8ac6-c46e857b90a1@d1g2000yqm.googlegroups.com>
References: <1f3174fa-fae3-42b6-8ac6-c46e857b90a1@d1g2000yqm.googlegroups.com>
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/534.30 (KHTML,
 like Gecko) Chrome/12.0.742.112 Safari/534.30,gzip(gfe)
Message-ID: <0c5bf67d-6755-42c6-975e-b0d436b3ba3b@y16g2000yqk.googlegroups.com>
Subject: Re: Problem parameterizing SQL window fuction
From: ashaner <asha...@chumpland.org>
To: pyodbc <pyodbc@googlegroups.com>
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Regarding the use of a parameter for the "top ?" portion I believe
you're c) doing something invalid. Why not just use python formatting
("...top %i..." % record)
instead?

On Jul 19, 2:33=A0pm, TheDavidFactor <thedavidfac...@gmail.com> wrote:
> code:
> =A0 =A0 record =3D 1
> =A0 =A0 statement =3D """SELECT * FROM (
> =A0 =A0 =A0 SELECT TOP 1 * FROM (
> =A0 =A0 SELECT TOP ? *
> =A0 =A0 FROM Inventory
> =A0 =A0 ORDER BY ID ASC
> =A0 ) AS FOO ORDER BY ID DESC
> ) AS BAR ORDER BY ID ASC"""
> =A0 =A0 print statement
> =A0 =A0 rows =3D self.cursor.execute(statement, record).fetchone()
>
> error:
> pyodbc.ProgrammingError: ('42000', "[42000] [Microsoft][SQL Server
> Native Client 10.0][SQL Server]Incorrect syntax near '@P1'. (102)
> (SQLExecDirectW); [42000] [Microsoft][SQL Server Native Client 10.0]
> [SQL Server]Statement(s) could not be prepared. (8180)")
>
> I've googled extensively and haven't found anything, that makes think
> that either a) I'm doing something stupid (more likely) or b) I'm
> trying to do something that's not very common (less likely)
>