Select * From table_a where charindex ('A', ID)> 0 or charindex ('B', ID)> 0
The ID field in Table _ A contains "A" or "B" records.
---------------------------------------------------
Charindex
Returns the starting position of the specified expression in the string.
Syntax
Charindex (expression1, expression2 [, start_location])
Parameters
Expression1
An expression that contains the order of characters to be searched. Expression1 is a short character data type classification expression.
Expression2
An expression is usually a column used to search for a specified sequence. Expression2 belongs to the string data type classification.
Start_location
Search for the start character position of expression1 in expression2. If start_location is not specified but is a negative number or zero, the search starts from the start position of expression2.
Return type
Int
Note
If either expression1 or expression2 belongs to the Unicode data type (nvarchar or nchar), the other is converted to the Unicode data type.
If either expression1 or expression2 is null, charindex returns NULL when the database compatibility level is 70 or greater. If the database compatibility level is 65 or more hours, charindex returns NULL only when both expression1 and expression2 are null.
If expression1 is not found in expression2, charindex returns 0.
Example
FirstCodeReturn the position where the sequence "wonderful" starts in the Notes column of the titles table. The second example uses the optional start_location parameter to search for "wonderful" starting from the fifth character in the Notes column ". The third example shows the result set when expression1 cannot be found in expression2.
Use pubs
Go
Select charindex ('Wonderful ', notes)
From titles
Where title_id = 'tc3218'
Go
-- Use the optional start_location parameter to start searching
-- For wonderful starting with the specified th character in the Notes
-- Column.
Use pubs
Go
Select charindex ('Wonderful ', notes, 5)
From titles
Where title_id = 'tc3218'
Go
The following is the result set of the first query and the second query:
-----------
46
(1 row (s) affected)
Use pubs
Go
Select charindex ('wondrous', notes)
From titles
Where title_id = 'tc3218'
Go
The following is the result set.
-----------
0
Address: http://wangqiaowqo.javaeye.com/blog/525750