我有一个SQL查询,它使用Do Until循环从数据库中检索值。循环内的SQLCondition值显示正确,但如果我想在循环外显示该值,它不起作用:
If rReseller > 0 Then
sql2 = "SELECT rl.countryid FROM reseller_locator rl WHERE rl.resellerid = " & rReseller & " AND rl.countryid <> '" & iCountryID & "'"
'response.write sql2
Set rsResellerLocator=Conn.Execute(sql2)
If not rsResellerLocator.EOF Then
do until rsResellerLocator.eof
iRCountryID = rsResellerLocator("countryid")
SQLCondition = iRCountryID & ", "
response.write SQLCondition
rsResellerLocator.movenext
loop
Else
SQLCondition = ""
End If
response.write SQLCondition
End If循环内部的response.write显示为"2,3,4,5“。但是来自循环外部的response.write显示为"5“。
如何将循环内部值存储到要在查询外部使用的字符串中?
发布于 2014-12-27 03:06:27
您确定内循环工作正常吗?我不明白为什么它会显示"2,3,4,5“--就像你现在的代码一样,它总是只显示一个数字。试试这个:
替换
SQLCondition = iRCountryID & ", "使用
SQLCondition = SQLCondition & ", " & iRCountryID这将保存条件字符串,否则只保存最新的条件
发布于 2018-08-17 20:43:45
使用此选项将所需数据保存为字符串
If rReseller > 0 Then
sql2 = "SELECT rl.countryid FROM reseller_locator rl WHERE rl.resellerid = " & rReseller & " AND rl.countryid <> '" & iCountryID & "'"
'response.write sql2
Set rsResellerLocator=Conn.Execute(sql2)
If not rsResellerLocator.EOF Then
do until rsResellerLocator.eof
iRCountryID = rsResellerLocator("countryid")
SQLCondition = iRCountryID & ", "
SQLConditionAll=""&SQLConditionAll&""&SQLCondition&""
response.write SQLCondition
rsResellerLocator.movenext
loop
Else
SQLCondition = ""
End If
response.write SQLCondition
End If
现在,您可以使用Response.write SQLConditionAll在字符串中显示所需数据
https://stackoverflow.com/questions/27660850
复制相似问题