
Untitled
By: a guest on
Jun 17th, 2012 | syntax:
None | size: 0.45 KB | hits: 17 | expires: Never
dynamic query generated by stored procedure or function
CREATE PROC Search(
@title VARCHAR(20) NULL, ...
AS SELECT * FROM your_table WHERE (title = @title OR @title IS NULL) etc.
public string BuildQuery(string[] columnNames, string tableName)
{
string query = string.Empty;
query = "SELECT ";
foreach(string str in columnNames)
query += str + ", ";
query = query.Substring(0, query.Length - 1);
query += " FROM " + tableName;
return query;
}