Getting Started with Adobe After Effects - Part 6: Motion Blur


Upload Image Close it
Select File

My Experiments with SQLServer
Browse by Tags · View All
SQLServer 126
SQLServer 2008 R2 91
SQLServer 2008 86
SQLServer 2005 82
SQL 60
Database 59
Sql And Me 57
Tips & Tricks 28
SQL Server 27
SQL FAQ 26

Archive · View All
May 2011 25
June 2011 21
July 2011 21
August 2011 19
April 2011 16
January 2013 4
May 2012 3
April 2012 3
October 2011 3
February 2013 2

Vishal Gajjar's Blog

SQL Functions – PATINDEX()

Jul 5 2011 7:52PM by Vishal Gajjar   

CHARINDEX() can only be used to search a literal string in the specified expression. In other words you cannot use wildcards. PATINDEX() provides this capability. It takes two arguments, the pattern to be searched and the expression.

– © 2011 – Vishal (http://SqlAndMe.com)
 
DECLARE @string VARCHAR(128)
SET @string =     'PATINDEX searches the string for the ' +
'first occurrence of a specified ' +
'character/String/pattern'
SELECT      PATINDEX('%s_t%', @string) AS 's t',
            PATINDEX('%pat%', @string) AS 'PATINDEX',
            PATINDEX('%pat[^i]%', @string) AS 'pattern',
            PATINDEX('%f[a-i]r%', @string) AS 'first' 

Result Set:

s t   PATINDEX  pattern  first
———–  ———–      ———–     ———–
17    1         87       38
 
(1 row(s) affected)

First column uses the _ Wildcard, which matches any one character, which is between 's' and 't'.

The second column uses % Wildcard, which searches for 0 or more characters. It is same as using: CHARINDEX('pat', @string).

Third column uses a ^ Wildcard, which matches the characters not matching the specified set. Hence, ignoring the 'PATINDEX'.

Last column matches the characters specified in the range using [ ] Wildcard. Since the set specifies that only 'a' to 'i', it ignores the 'for'.

Pattern matching is based on the data collation. We can use COLLATE to enforce a case-sensitive search:

SELECT      PATINDEX('%[S]tring%', @string) AS 'string',
            PATINDEX('%[S]tring%', @string COLLATE Latin1_General_CS_AI)
            AS 'String'

Result Set:

string      String
———–        ———–
23          80
 
(1 row(s) affected)

Hope This Helps! Cheers!


Republished from Sql&Me [31 clicks].  Read the original version here [32134 clicks].

Vishal Gajjar
46 · 4% · 1276
0
Liked
 
0
Lifesaver
 
0
Refreshed
 
0
Learned
 
0
Incorrect



Submit

Your Comment


Sign Up or Login to post a comment.

    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]