我正在尝试使用经典的ASP和SQL Server从数据库中为矢量的每个位置选择结果。到目前为止的代码:
FOR EACH x IN Tabela
sql = "SELECT DISTINCT tborders.family AS family, tborders.qty AS qty, tborders.los AS los, CONVERT(DATE, tborders.mrd_date) AS mrd FROM [DASH].[dashboard_db].[dbo].[tb_family] AS tbfamily INNER JOIN [DASH].[dashboard_db].[dbo].[tb_started_zero] AS tborders ON tbfamily.[family] = tborders.[family] WHERE tborders.[Order Number] = "&x&""
SET rs = conn.execute(sql)
IF rs.EOF = false THEN
mrd(counter) = rs("mrd")
family(counter) = rs("family")
los(counter) = rs("los")
qty(counter) = rs("qty")
counter=counter+1
END IF
NEXT
请注意,tborders.[Order Number]
是一个int
类型的值。由于某种原因,我遇到了此错误:
Microsoft SQL Server本机客户端11.0错误'80040e14'
'='附近的语法不正确。
/asplearning/act/validate-schedule-line.asp,第46行
我尝试删除SET
,但是然后我的结果集未被识别为对象。我已经试过了,我敢肯定这些类型都很好:
if isNumeric(x) THEN
response.write("<h1>it is numeric</h1>")
else
response.write("<h1>not numeric</h1>")
end if
并且它为Tabela
的每个位置写了“它是数字”。任何人都可以帮助解决似乎存在的问题吗?
答案 0 :(得分:0)
看起来您有一个空项目(集合的第一个或最后一个项目)。
我强烈建议您使用sp_executesql。这将使用编译的执行计划,并且将验证您的参数(反对sql注入)。
FOR EACH x IN Tabela
if len(x) > 0 then
sql = "exec sp_executeSql N'SELECT DISTINCT tborders.family AS family, tborders.qty AS qty, tborders.los AS los, CONVERT(DATE, tborders.mrd_date) AS mrd FROM [DASH].[dashboard_db].[dbo].[tb_family] AS tbfamily INNER JOIN [DASH].[dashboard_db].[dbo].[tb_started_zero] AS tborders ON tbfamily.[family] = tborders.[family] WHERE tborders.[Order Number] = @OrderNumber', N'@OrderNumber int', @orderNumber = " & x
SET rs = conn.execute(sql)
IF rs.EOF = false THEN
mrd(counter) = rs("mrd")
family(counter) = rs("family")
los(counter) = rs("los")
qty(counter) = rs("qty")
counter=counter+1
END IF
rs.close
end if
NEXT