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 ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| 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! |
| |||
| 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 > > |
| ||||
| 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 |
| Thread Tools | |
| Display Modes | |
|
|