Examples of how to use charindexcharindex('test', 'This is for testing.')
When executing charindex as above, it would return 13 as the result. charindex looks for "test" in the character string "This is for testing."
charindex('test', 'testing')
When executing charindex as above, it would return 1 as the result. This is the very first position when working with charindex.
charindex('test', 'The searchstring is not here.')
When executing charindex as above, it would return 0 as the result. charindex looks for "test" in "The searchstring is not here." and cannot find "test".
charindex can be combined with a select statement as follows:
SELECT charindex(' ',colname)
FROM tablename;
This would result in the first position of a space that charindex comes across. |