ASP中巧用Split()函数生成SQL查询语句
2002-10-31 10:23:29 来源:WEB开发网核心提示:Split 程序代码<%attribs="商场名^^快餐店名^^报停名"names=Split(attribs,"^^")i=0for each name in namesresponse.write names(i)&"<br>"i=i+1
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
<%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
- ››asp.net页面弄成伪静态页面
- ››Asp.net 中将汉字转换成拼音的方法
- ››ASP.NET及JS中的cookie基本用法
- ››ASP.NET获取MS SQL Server安装实例
- ››asp.net实现调用百度pai 在线翻译英文转中文
- ››ASP.NET页面选项进行提示判断
- ››Asp.net定时执行程序
- ››ASP.NET中利用DataList实现图片无缝滚动
- ››ASP.NET验证控件RequiredFieldValidator
- ››ASP.NET中使用System.Net.Mail发邮件
- ››ASP.NET中获取用户控件中控件的ID
- ››ASP.NET中FileBytes写成文件并存档
更多精彩
赞助商链接