SQL语句求救?问题解决马上给分!快来救命呀!
select * from User where ID in ()
我有一条sql语句类似上面,但是后面in里面是一个组数,例如
string[] aaa = {123,345,5676,sadf}
我整个语句的意思是从User表里搜索ID,但是ID必须在数组aaa中,
大家能不能在这条SQL语表中把完整的语句写出来,谢谢了.
------解决方案--------------------ID是varchar类型的吗?
string sql = "select * from User where ID in ( ";
foreach (string a in aaa)
{
sql += " ' " + a + " ', ";
}
sql = sql.Substring(0, sql.Length - 1);
sql += ") ";
没有测试
------解决方案--------------------string strSql= "select * from User where ID in ( ";
for(int i=0;i <aaa.length;i++)
{
strSql+= aaa[i]+ ", ";
}
strSql= strSql.Remove(sql.Length - 1);
strSql+= ") ";