Crystal Reports & SQL Reporting Services Training Consultants
Account Log in:
Username:
Password:
A setback is the opportunity to begin again more intelligently
 
Institute of IT Trainers - Freelance Trainer of the Year 2006 & 2009
Liverpool Business Connect Member
  Maximum Impact Solutions Limited - Reporting Solutions, Creating Answers
Reporting Solutions - Creating Answers, Crystal Reports, Dashboarding (Xcelsius) & SQL Reporting Services

The Maximum Impact Solutions Blog Feed ME!!!!

30
March

How Do I Find the Position of a Specific Character in a String Field?

I was recently asked during a SQL Reporting Services training session, how does one find a position of a specified character in a string field.

Solution

To find the position of a specified character in a string field, one can use the function CHARINDEX.

The CHARINDEX function has 3 arguments:
  • Search Text
  • String to be searched
  • Starting Position


To find the first space position in a string field:

CHARINDEX( ' ', {Tablename.Fieldname}, 1)


To find the second space position in a string field:

CHARINDEX(' ', {Tablename.Fieldname},1+CHARINDEX(' ', {Tablename.Fieldname},1))


To find the first space postion starting from the right of a string field:

Unfortunately there is not an SQL function to directly extract characters in a string field, starting from the right.  To get around this one can use the REVERSE function

CHARINDEX(' ',REVERSE({Tablename.Fieldname}),1)



If you have any questions, leave us a comment below, or need any assistance, please do not hesitate to Contact Us
1

Smithe769

02
June
This actually answered my drawback, thank you!
2

John

11
June
Very nice site!

MAKE A COMMENT

Name *

Email Address *

Comment *