0

刚刚更新了我的问题。但我有一个数组

Dim divName(3) 'Fixed size array
divName(0) = "DIV1"
divName(1) = "DIV2"
divName(2) = "DIV3"

我想在我的 SQL 查询中应用我的数组中的一个特定值(“DIV1”)

sql = "SELECT * FROM DivisionNew814 WHERE JMS_UpdateDateTime >= DATEADD(day,-7, GETDATE()) AND  Division ='" & divName (divrec(0)) &"' order by JMS_UpdateDateTime desc" 

它不工作。

“Divrec”是一个输出到“Division 1”的变量我想在 SQL 查询中使用我的数组将该值更改为“DIV1”。

4

3 回答 3

1
<%
if divrec = "Division 1" then
  divrec = "Div1"
end if
%>
于 2013-08-18T22:17:49.323 回答
1

要输出数组值,您需要使用索引:

Dim divName(3) 'Fixed size array
divName(0) = "DIV1"
divName(1) = "DIV2"
divName(2) = "DIV3"


... AND  Division ='" & divName(0) &"' order by ...

如果您需要从“Division 1”到“DIV1”的转换,并且如果它总是像“Division X”到“DIVX”,您可以替换:

... AND  Division ='" & Replace(divrec(0), "Division ", "DIV") &"' order by ...
于 2013-08-19T05:34:44.890 回答
0

听起来您需要的是一个键值集合,这意味着可以将文本“Division 1”“翻译”为“DIV1”。为此,我们有 Scripting.Dictionary 对象:

Dim divNames
Set divNames = Server.CreateObject("Scripting.Dictionary")
divNames.Add "Division 1", "DIV1"
divNames.Add "Division 2", "DIV2"
divNames.Add "Division 3", "DIV3"

进而:

sql = "SELECT * FROM DivisionNew814 WHERE JMS_UpdateDateTime >= DATEADD(day,-7, GETDATE()) AND  Division ='" & divNames(divrec(0)) &"' order by JMS_UpdateDateTime desc" 

如果divrec只是一个字符串,则更改为:

sql = "SELECT * FROM DivisionNew814 WHERE JMS_UpdateDateTime >= DATEADD(day,-7, GETDATE()) AND  Division ='" & divNames(divrec) &"' order by JMS_UpdateDateTime desc"
于 2013-08-19T14:31:11.340 回答