11.12.2006, 18:17
общий
это ответ
Здравствуйте, DmitryDE!
В MS SQL Server‘е есть функция SUBSTRING. Вот синтакс:
Syntax
SUBSTRING ( expression , start , length )
Arguments
expression
Is a character string, binary string, text, image, a column, or an expression that includes a column. Do not use expressions that include aggregate functions.
start
Is an integer that specifies where the substring begins.
length
Is an integer that specifies the length of the substring (the number of characters or bytes to return).
Для определения начальной позиции используйте функйию PATINDEX:
PATINDEX
Returns the starting position of the first occurrence of a pattern in a specified expression, or zeros if the pattern is not found, on all valid text and character data types.
Syntax
PATINDEX ( ‘%pattern%‘ , expression )
Arguments
pattern
Is a literal string. Wildcard characters can be used; however, the % character must precede and follow pattern (except when searching for first or last characters). pattern is an expression of the short character data type category.
expression
Is an expression, usually a column that is searched for the specified pattern. expression is of the character string data type category.
Return Types
int
Remarks
PATINDEX is useful with text data types; it can be used in a WHERE clause in addition to IS NULL, IS NOT NULL, and LIKE (the only other comparisons that are valid on text in a WHERE clause).
If either pattern or expression is NULL, PATINDEX returns NULL when the database compatibility level is 70. If the database compatibility level is 65 or earlier, PATINDEX returns NULL only when both pattern and expression are NULL.
Examples
A. Use a pattern with PATINDEX
This example finds the position at which the pattern "wonderful" begins in a specific row of the notes column in the titles table.
USE pubs
GO
SELECT PATINDEX(‘%wonderful%‘, notes)
FROM titles
WHERE title_id = ‘TC3218‘