Home > Database > Mysql Tutorial > SQL多条件查询拼接in中条件方法

SQL多条件查询拼接in中条件方法

WBOY
Release: 2016-06-07 17:20:52
Original
2919 people have browsed it

做了一个功能,就是前台可以选择同一字段下面的多个不同的条件,这就涉及到了SQL语句拼接的问题。下面是一个用正则来处理查询条件

做了一个功能,就是前台可以选择同一字段下面的多个不同的条件,这就涉及到了SQL语句拼接的问题。

下面是一个用正则来处理查询条件的方法,是我目前所见到最简单的方法,现将它分享给大家。

using System.Text;

using System.Text.RegularExpressions;

string  strwhere="1,11,111,1111,";

strwhere = string.Format("select

 * from test where strwhere in ({0})",Regex.Replace(strwhere.TrimEnd(','), @"[^,]+", "'$0'"));

注:这里strwhere.TrimEnd(',')用来将1111后面的逗号去掉。

linux

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template