Monday 13 June 2011

SQL Charindex and PatIndex


We can use either CHARINDEX or PATINDEX to search in TEXT field in SQL SERVER. The CHARINDEX and PATINDEX functions return the starting position of a pattern you specify.
    Its usefull tips. You can use both the things whenever required.
Example of CHARINDEX:
USE LIMS;
GO
SELECT CHARINDEX('ensure', DocumentSummary)
FROM SC_Workorder
WHERE DocumentID = 3;

GO
Examples of PATINDEX:

USE LIMS;
GO
SELECT PATINDEX('%ensure%',DocumentSummary)
FROM SC_Workorder
WHERE DocumentID = 3;

GO

No comments:

Post a Comment