Unix Technical Forum

parameter query

This is a discussion on parameter query within the SQL Server forums, part of the Microsoft SQL Server category; --> Hi, The following parameter query resulted the error below. Is the following syntax correct? select * from branch where ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 05:55 PM
John Jayaseelan
 
Posts: n/a
Default 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!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-28-2008, 05:55 PM
Danilo Popovic
 
Posts: n/a
Default Re: parameter query

I asked same question. ;-)

> You can't use parameters with a view. If you have MSSQL2000, then you

could
> use a table-valued function:
>
> create function dbo.GetProducts (@ProductID int)
> returns table
> as
> return (select ProductID, NameOfProduct from dbo.Products where ProductID

<
> @ProductID)
>
> select * from dbo.GetProducts(5)
>
> Otherwise, you can use a stored procedure.
>
> Simon
>
>





Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-28-2008, 05:56 PM
Erland Sommarskog
 
Posts: n/a
Default Re: parameter query

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


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:

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


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
http://www.microsoft.com/sql/techinf...2000/books.asp
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 09:47 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com