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 – CHARINDEX()

Jul 4 2011 1:59PM by Vishal Gajjar   

CHARINDEX() returns the starting position of an expression in another expression. It takes below arguments:

CHARINDEX ( exp1, exp2, position )

Where, exp1 = expression to be searched,

exp2 = the main expression which contains exp1,

position = this is optional, it specifies a position in exp2 from which the search for exp1 starts.

CHARINDEX() returns and INT/BIGINT based on the data type of exp2, which specifies the starting point of exp1. For data types declared with (MAX) it returns BIGINT.

-- © 2011 – Vishal (http://SqlAndMe.com)
 
DECLARE @string VARCHAR(128)
SET @string =     'CHARINDEX searches for the string for the ' +
                  'first occurrence of a specified character/string'
SELECT      CHARINDEX('Char', @string)    AS 'Position',
            CHARINDEX('Char', @string, 2) AS 'Position'

Result Set:

Position    Position
———–        ———–
1           75
 
(1 row(s) affected)

In the above example, the first columns returns 1 as the string started with 'CHAR…', while in the second column the search was started from 'HARINDEX…', which resulted in returning the second occurrence of 'CHAR'.

Searches are based on the collation of the data. CHARINDEX() has performed a case-insensitive search as my current collation is set to Latin1_General_CI_AI. To perform a case-sensitive search here we can apply Latin1_General_CS_AI collation to @string:

DECLARE @string VARCHAR(128)
SET @string =     'CHARINDEX searches for the string for the ' +
                  'first occurrence of a specified character/string'
SELECT      CHARINDEX('char', @string COLLATE Latin1_General_CS_AI)
            AS 'Position'

Result Set:

Position
———–
75
 
(1 row(s) affected)

In this example, the first occurrence of 'Char' is ignored as it does not match the case.

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]