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

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-07 17:20:52
Original
3006 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:
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
Latest Issues
sql file
From 1970-01-01 08:00:00
0
0
0
php - Overhead of prepare vs sql?
From 1970-01-01 08:00:00
0
0
0
Print sql statement
From 1970-01-01 08:00:00
0
0
0
Pass array to SQL insert query using PHP
From 1970-01-01 08:00:00
0
0
0
sql optimization or
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template