What is the best FUNCTION to search for a character inside a string sql?
I've been trying to search if there exists a character inside a fixed string.
For example I have:
1OF2. 040713 08:07 AM
And I want to know if there is a '.' inside the string.
Use like:
select col like '%.%'
It is standard SQL and SQL Server has some good optimizations built into the query engine to handle it.
EDIT (in response to a comment):
Getting the first part of the string is a bit different. In that case:
select (case when col like '%.%' then left(col, charindex('.', col) - 1)
else col
end)
CHARINDEX is also available. Use CHARINDEX and compare against 0 (not found). For example:
SELECT *
WHEN CHARINDEX('.',field) > 0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With