0

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?

Edited by sid78669: Correcting information

2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by sid78669
0

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
    }
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.