Hey Guys,

So I'm working on an ASP page and I am making use some select statement. Now, I need to specify a where clause and make the only condition in there optional, i.e.:

SELECT * from table where Upper(name) LIKE "SID"

I want to make

where Upper(name) LIKE "SID"

optional here. That is if, I pass "SID", it does the where clause, other wise it just does a select.

Any suggestions?

Recommended Answers

All 2 Replies

You need to construct the query dynamically in your .ASP page's code-behind file.

private void button1_Click(object sender, EventArgs e)
    {
      StringBuilder Sql = new StringBuilder();
      Sql.AppendLine("Select *");
      Sql.AppendLine("From Table");
      if (!string.IsNullOrEmpty(textBox1.Text))
      {
        Sql.AppendLine(string.Format("Where Name Like '{0}'", textBox1.Text));
      }
      string query = Sql.ToString();
      //Execute the query
    }

Thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.