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?


Login to See the Rest of the Answer

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.






For peering opportunity Autonomouse System Number: AS401345 Custom Software Development at ErnesTech Email AddressContact: [email protected]