Hi there,
First thing is first.
Use SQL parameters in your query.
const string connectionStringName = "MyConnectionString";
var searchText = "something";
using (var connection = new SqlConnection(ConfigurationManager.ConnectionStrings[connectionStringName].ToString()))
{
using (var command = connection.CreateCommand())
{
command.CommandType = CommandType.Text;
command.CommandText = "SELECT U.UserName as 'ID', U.FirstName + ' ' + U.LastName as 'Name' from [Users] U WHERE U.UserName LIKE @SearchText OR U.FirstName LIKE @SearchText OR U.LastName LIKE @SearchText";
var searchParameter = new SqlParameter("SearchText", searchText);
command.Parameters.Add(searchParameter);
connection.Open();
var reader = command.ExecuteReader();
}
}
Use Google or numerous articles on CodeProject to learn anything you don't understand in the above code block.
Now regarding your question. I've created a temp table and run your query like the way you have asked. It does NOT return any duplicates. Perhaps, you might have a different idea of what is a 'duplicate' or you might be trying to achieve something else. Please, explain what this SQL should return data-wise. Are you expecting just one row satisfying the search conditions?