当前位置:主页 > 查看内容

ASP中巧用Split()函数生成SQL查询语句的实例

发布时间:2021-04-26 00:00| 位朋友查看

简介:Split 程序代码 复制代码 代码如下: %attribs="商场名^^快餐店名^^报停名" names=Split(attribs,"^^") i=0 for each name in names response.write names(i)"br" i=i+1 next % 程序拆分结果: 商场名 快餐店名 报停名 根据 Split 结果生成 SQL 语句 复制代码……

Split 程序代码

复制代码 代码如下:

<%attribs="商场名^^快餐店名^^报停名"
names=Split(attribs,"^^")
i=0
for each name in names
  response.write names(i)&"<br>"
  i=i+1
next
%>

程序拆分结果:
商场名
快餐店名
报停名

根据 Split 结果生成 SQL 语句

复制代码 代码如下:

<%attribs="商场名^^快餐店名^^报停名"
names=Split(attribs,"^^")
i=0
sql="select top 10 * from TableName where"
for each name in names
  if names(i)="商场名" then
    sql=sql+" or 商场 like '%"&names(i)&"%'"
  end if
  if names(i)="快餐店名" then
    sql=sql+" or 快餐店 like '%"&names(i)&"%'"
  end if
  if names(i)="报停名" then
    sql=sql+" or 快餐店 like '%"&names(i)&"%'"
  end if
  i=i+1
next
sql=sql+" Ordey by Id DESC"
sql=Replace(sql, "where or", "where")
response.write sql
%>

程序运行结果:

复制代码 代码如下:

select top 10 * from TableName where 商场 like '%商场名%' or 快餐店 like '%快餐店名%' or 快餐店 like '%报停名%' Ordey by Id DESC


原文链接:https://m.jb51.net/article/49040.htm
本站部分内容转载于网络,版权归原作者所有,转载之目的在于传播更多优秀技术内容,如有侵权请联系QQ/微信:153890879删除,谢谢!

推荐图文


随机推荐