Greetings, fellow monks

I seek some DBI wisdom.

I am using the following code to extract some data from our MS-SQL database using Perl version 5.8.8: (I've snipped out the irrelevant stuff for clarity and conciseness)

use strict; use warnings; use DBI; <snip> my $dbh=DBI->connect('dbi:ODBC:DSN='.$DSN, $USER, $PSWD) or die "Could +n't connect to database: ".DBI->errstr; my $fieldquery=" SELECT <Snip> FROM <Snip> WHERE PlanSetup.PlanSetupSer=? <snip the rest of the where clause> "; my $sth_fields=$dbh->prepare($fieldquery) or die "Couldn't prepare sta +tement: " . $dbh->errstr; <Snip some stuff to get $plansetupser> $sth_fields->execute($plansetupser) or die "Couldn't execute statement +: ".$sth_fields->errstr;

The trouble is, when I try to run this statement, I always get the error message:

 Couldn't execute statement: called with 1 bind variables when 0 are needed at line <snip>

I just don't understand why it says that it doesn't need a bind variable when I have definitely put a question mark in the SQL. I've tried various other things instead of the question mark, like :parameter, but these have the same effect. There's clearly something up with my syntax, but I'm stumped as to what it is...

I hope this is enough to go on, and thanks in advance for any help!

In reply to I seek DBI wisdom concerning bind parameters by campbell

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.