title: how can i set the parameters for the sql query optional?
body: <p>I build a Web Service in ASP.Net which sends me a list of rooms.</p>
  
  <p>The parameters are id's which are separated by a comma.</p>
  
  <p>I saved them to a string and build a sql select query.</p>
  
  <p>When I send all 4 parameters I everything works fine and I get a result. But when I send less then 4 I get an error. </p>
  
  <pre><code>System.Data.SqlClient.SqlException: Incorrect syntax near ')'.
  </code></pre>
  
  <p>How can I set my the parameters optional in the sql query to select just the values I entered?</p>
  
  <p>Here is my code so far: </p>
  
  <pre><code>internal static List&lt;RAUM&gt; Raum(string RAUMKLASSE_ID, string STADT_ID, string GEBAEUDE_ID, string REGION_ID)
  {
      List&lt;RAUM&gt; strasseObject = new List&lt;RAUM&gt;();
      string raumklasseid = RAUMKLASSE_ID;
      string gebaudeid = GEBAEUDE_ID;
      string stadtid = STADT_ID;
      string regionid = REGION_ID;
  
      using (SqlConnection con = new SqlConnection(@"Data Source=Localhost\SQLEXPRESS;Initial Catalog=BOOK-IT-V2;Integrated Security=true;"))
      using (SqlCommand cmd = new SqlCommand(@"SELECT r.BEZEICHNUNG AS BEZEICHNUNG, r.ID AS ID FROM RAUM r WHERE RAUMKLASSE_ID IN (" + raumklasseid + ") AND STADT_ID IN (" + stadtid + ") AND GEBAEUDE_ID IN (" + gebaudeid + ") AND REGION_ID IN (" + regionid + ")", con))
      {
          con.Open();
  
          using (SqlDataReader rdr = cmd.ExecuteReader())
          {
              while (rdr.Read())
              {
                  if (rdr["BEZEICHNUNG"] != DBNull.Value &amp;&amp; rdr["ID"] != DBNull.Value)
                  {
                      strasseObject.Add(new RAUM()
                      {
                          RaumName = rdr["BEZEICHNUNG"].ToString(),
                          RaumID = rdr["ID"].ToString()
                      });
                  }
              }
          }
      }
  
      return strasseObject;
  }
  </code></pre>
  
  <p>Thanks in advance for your help.</p>