使用数组动态赋值SQL IN ()条件

VB
sql = "SELECT * FROM TABLE WHERE AA IN (" '初始化查询字符串
For i = 0 to UBound(Ary) '从0循环到数组最大下标
sql = sql & Ary(i) & "," '将数组中每个值加在查询字符串后面
Next
sql = Left(sql,Len(sql)-1) & ")" '将最后一个逗号换为反括号

C#

static void Main(string[] args)
{
string str = "aaaa,bbbb,cccc,dddd,eeee";

string[] condititons = str.Split(',');


string ss = "select * from table where aa in (";
for(int i=0;i<condititons.Length;i++)
{
ss = ss+condititons[i]+",";
}
//sql.Substring(0,sql.Length-1);
//ss = ss.Substring(0,sql.Length-1);
ss = ss.Substring(0,ss.Length-1);
ss = ss +")";
Console.WriteLine(ss);

}
}

java

String[] strs = {"01", "02"}

String strTemp ="";
try {
for (int k = 0; k < strs.length; k++) {
strTemp += strs[k] + ",";
}
strTemp = strTemp.substring(0, strTemp.length() - 1); // 将最后一个逗号去掉
String sql = "select* from user_status_t wherestatus in (" + strTemp +")";

你可能感兴趣的:(sql,C++,c,C#,vb)