-2
string[] questions= new[] { "2","5","1","11","3","1"};

    select description,count(description) 
      from descriptions 
inner join questions 
        on descriptions.qid=questions.id 
     where descriptions.question=N'hardtest' 
       and qid in (?) 
  group by description

I want to use an array in this code as an input to IN clause. How can I do that?

qid in ('" + list + "')
Sunil
  • 3,404
  • 10
  • 23
  • 31

1 Answers1

2
string[] questions = new[] { "2", "5", "1", "11", "3", "1" };

string qids = string.Empty;
questions.All((x) => { qids += "','" + x; return true; });
qids = qids.Substring(2);

string sql = @"
select description, count(description)
  from descriptions
inner join questions
    on descriptions.qid = questions.id
where descriptions.question = N'hardtest'
   and qid in ("+qids+@"')
group by description";
wangguanguo
  • 181
  • 4