I have a parameterized query that looks like this:
SELECT title, html, shortname FROM dbo.Videos
WHERE Topic_ID = ? AND dbo.gradeLevelCheck(?, Grade_Lower, Grade_Upper) = 1
ORDER BY shortname ASC
When I run it from ASP, I get an error that reads:
Incorrect syntax near the keyword 'from'
The parameters are 56 and 1 (so no nulls). The stored function dbo.gradeLevelCheck looks like this:
ALTER FUNCTION [dbo].[gradeLevelCheck]
(
@value int,
@lower int,
@upper int
)
RETURNS int
AS
BEGIN
DECLARE @result int;
IF (@lower IS NULL OR @lower <= @value) AND (@upper IS NULL OR @upper >= @value)
SET @result = 1;
ELSE
SET @result = 0;
RETURN @result;
END
It works fine if I submit it with the parameters hardcoded into the query. It also works fine if I remove the ORDER BY clause. But I can't get it to work in this form. Can anyone help me figure out why?
EDIT: Here are some additional details. The application is written in Classic ASP with JScript. The connection is established thus:
var conn = Server.CreateObject('ADODB.Connection');
var connectionString =
'Provider=SQLOLEDB;' +
'Data Source=' + Settings.dbServer + ';' +
'Initial Catalog=' + Settings.dbCatalog + ';' +
'User Id=' + Settings.dbUser + ';' +
'Password=' + Settings.dbPass + ';' +
'Connect Timeout=15;';
conn.Open(connectionString, conn);
The code used to submit the query looks like this:
DB.query = function(query) {
...
var cmd = Server.CreateObject("ADODB.Command");
cmd.activeConnection = conn;
cmd.commandText = query;
for (var i = 1; i < arguments.length; i++) {
cmd.Parameters(i-1).value = arguments[i];
}
return cmd.Execute();
...
}
(Here, the parameters 1 and 56 are passed as additional arguments to DB.query.)
DB.queryfrom this site: blogs.technet.com/b/neilcar/archive/2008/05/21/…