SQL Query Like does not work with Spaces in a String

Question: How do you get the TSQL Like keyword to work with spaces in the String Value?

Answer: You will have to replace the Space or Spaces in your String or Value passed to the SQL Server. See the example of C# (C-Sharp) code below:

 public async Task<List<YourClassModel>> SearchByMyValue(string myAwesomeValue)
        {
            
            string cleanedAwesomeValue = myAwesomeValue.Replace(" ","%");
//Then you can pass the cleanedAwesomeValue to the Database
}

//Sql Store Procedure
You can now use "LIKE" to search for cleanedAwesomeValue passed in as Store Proc Arguments

- In some other cases, you can just trim the values you are sending to the database by using a Trim() function built-in C-Sharp.
For example, myValueString.Trim() this will almost if at all give you the same results.


Edit this Article
SQL Like does not work with spaces in parameter Technology published
Was this page helpful?
Yes Yes! this solution to the problem was helpful. No No! this solution to the problem was not helpful.. Leave ErnesTech Feedback.Feedback
If you log in, you will be notified when someone leaves a comment.

Other users would like to know if this solution helped you.

Your Session is Ending
Login to Continue

© 2021 - ErnesTech - Privacy