| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 444 人关注过本帖
标题:拼sql问题
只看楼主 加入收藏
sm105096496
Rank: 1
等 级:新手上路
帖 子:58
专家分:0
注 册:2007-7-11
收藏
 问题点数:0 回复次数:1 
拼sql问题

public DataTable ShowFindscout(string name,string verid)
{
string strline=name;
string [] aryline=null;
string ss="";
aryline = strline.Split(new char[] { ',' });
if(aryline.Length>=2)
{
for (int j = 0; j< aryline.Length; j++)
{
if (j==(aryline.Length-1))
{
ss=ss+"Coupon LIKE '%" +aryline[j]+"%' or "+"Chrcontent LIKE '% or "+aryline[j]+"%' or "+"Keyword LIKE '%"+aryline[j]+"%'";

}
else
{
ss=ss+"Coupon LIKE '%" +aryline[j]+"%' or "+"Chrcontent LIKE '% or "+aryline[j]+"%' or "+"Keyword LIKE '%"+aryline[j]+"%' or ";
}
}
}
else
{
for (int j = 0; j< aryline.Length; j++)
{
ss="Coupon LIKE '%" +aryline[j]+"%' or "+"Chrcontent LIKE '%"+aryline[j]+"%' or "+"Keyword LIKE '%"+aryline[j]+"%'";
}
}
myConn.dbQuery("select Nid,Chrtitle,Chrcontent,Dtappenddate from Life_find where Isopen=1 and verid="+verid+" and ("+ss+") ");
return myConn.FileValue;
}
上面是我写的代码 传值例如:a,b,c
得到 SQL入下

select * from where verid=2 and (Coupon LIKE '%a' or Chrcontent LIKE '%a' Keyword LIKE '%a' or Coupon LIKE '%b' or Chrcontent LIKE '%b' Keyword LIKE '%b' or Coupon LIKE '%c' or Chrcontent LIKE '%c' Keyword LIKE '%c')

现在想把上面的方法改下 传值成 a,b,c|A,B,C
得到SQL如下:请帮我改下

select * from where verid=2 and (Coupon LIKE '%a' or Chrcontent LIKE '%a' Keyword LIKE '%a' or Coupon LIKE '%b' or Chrcontent LIKE '%b' Keyword LIKE '%b' or Coupon LIKE '%c' or Chrcontent LIKE '%c' Keyword LIKE '%c') and (Coupon LIKE '%A' or Chrcontent LIKE '%A' Keyword LIKE '%A' OR Coupon LIKE '%B' or Chrcontent LIKE '%B' Keyword LIKE '%B')

搜索更多相关主题的帖子: sql 
2007-09-11 16:18
yms123
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:209
帖 子:12488
专家分:19042
注 册:2004-7-17
收藏
得分:0 

private string getLIKEQueStr(string tstr)
{
string ss="(";
string[] aryline=tstr.split(',');
for(int j = 0; j< aryline.Length; j++)
{
ss=ss+"Coupon LIKE '%" +aryline[j]+"%' or ";
ss=ss+"Chrcontent LIKE '% or "+aryline[j]+"%' or ";
ss=ss+"Keyword LIKE '%"+aryline[j]+"%' or ";
}
ss=ss.substr(1,ss.length-4);
ss+=")";
return ss;
}

public DataTable ShowFindscout(string name,string verid)
{
string ss="";
string strline=name;
string[] arystr=name.split('|');
for(var i=0;i<arystr.length;i++)
{
ss+=this.getLIKEQueStr(arystr[i])+" and ";
}
ss=ss.substr(1,ss.length-5);
myConn.dbQuery("select Nid,Chrtitle,Chrcontent,Dtappenddate from Life_find where Isopen=1 and verid="+verid+" and ("+ss+") ");
return myConn.FileValue;
}
函数长的时候可以进行分函数写。

2007-09-11 21:54
快速回复:拼sql问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.020238 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved