SQL Tips n Tricks: CHARINDEX Transact-SQL

I was looking at some code generated by the compiler for an IQueryable that I created and found this built-in function that I’ve never used before.  I can see it being very useful when doing string compares.

CHARINDEX (Transact-SQL)
expressionToFind
Is a character expression that contains the sequence to be found. expressionToFind is limited to 8000 characters.

expressionToSearch
Is a character expression to be searched.

start_location
Is an integer or bigint expression at which the search starts. If start_location is not specified, is a negative number, or is 0, the search starts at the beginning of expressionToSearch.

If either expressionToFind or expressionToSearch is of a Unicode data type (nvarchar or nchar) and the other is not, the other is converted to a Unicode data type. CHARINDEX cannot be used with textntext, and image data types.

via CHARINDEX Transact-SQL.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s