I'm trying to select results from a database for each position of a vector using classic ASP and SQL Server. The code so far:
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
Taking note that tborders.[Order Number]
is a int
typed value. For some reason I'm having this error:
Microsoft SQL Server Native Client 11.0 error '80040e14'
Incorrect syntax near '='.
/asplearning/act/validate-schedule-line.asp, line 46
I have tried removing the SET
, but then my result set isn't recognized as a object. I'm pretty sure that the types are just fine, I have tried:
if isNumeric(x) THEN
response.write("<h1>it is numeric</h1>")
else
response.write("<h1>not numeric</h1>")
end if
And it has written "it is numeric" for each position of Tabela
. Can anyone help with what it seems to be the problem?
It's look you have an empty item (first or last item of the collection).
I strongly suggest you to use sp_executesql. This will use a compiled execution plan, and this will validate your parameters (against sql injection).
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.