parameter query

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John Jayaseelan

    parameter query

    Hi,

    The following parameter query resulted the error below. Is the following
    syntax correct?

    select * from branch where branch_code = ?


    [Microsoft][ODBC SQL Server Driver]COUNT field incorrect or syntax error


    Thanks

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
  • Danilo Popovic

    #2
    Re: parameter query

    I asked same question. ;-)
    [color=blue]
    > You can't use parameters with a view. If you have MSSQL2000, then you[/color]
    could[color=blue]
    > use a table-valued function:
    >
    > create function dbo.GetProducts (@ProductID int)
    > returns table
    > as
    > return (select ProductID, NameOfProduct from dbo.Products where ProductID[/color]
    <[color=blue]
    > @ProductID)
    >
    > select * from dbo.GetProducts (5)
    >
    > Otherwise, you can use a stored procedure.
    >
    > Simon
    >
    >[/color]




    Comment

    • Erland Sommarskog

      #3
      Re: parameter query

      John Jayaseelan (john.jayaseela n@caravan-club.co.uk) writes:[color=blue]
      > The following parameter query resulted the error below. Is the following
      > syntax correct?
      >
      > select * from branch where branch_code = ?[/color]

      Depends on which context you issued it in. It is not legal T-SQL. If you
      run this from ISQL, which uses DB-Library that does not intercept the
      SQL string, you get:

      Msg 170, Level 15, State 1, Server KES-METS-, Line 1
      Line 1: Incorrect syntax near '?'.

      But if you run it from Query Analyzer, you get a more puzzling mesage:
      [color=blue]
      >[Microsoft][ODBC SQL Server Driver]COUNT field incorrect or syntax error[/color]

      Note here that it does not say [SQL Server]. So this message comes from
      the ODBC driver, because in the ODBC syntax, the ? is a special token
      for a parameter holder. I don't the ODBC syntax well, so I cannot say
      whether you can actually use this syntax successfully from QA. Normally,
      you use this syntax when you pass SQL statements from application code.

      --
      Erland Sommarskog, SQL Server MVP, sommar@algonet. se

      Books Online for SQL Server SP3 at
      SQL Server 2025 redefines what's possible for enterprise data. With developer-first features and integration with analytics and AI models, SQL Server 2025 accelerates AI innovation using the data you already have.

      Comment

      Working...