How to obtain the Number of chrs left of a specifed chr using an sql statement.

Contributed by
Rating: 5 stars5 stars5 stars5 stars5 stars / 1
October 22, 2000
Rate this Article:
MEH MEH++


SEARCH ASP FREE
TOOLS YOU CAN USE

advertisement

How to optain the Number of chrs left of a specifed chr using an sql statement.

I want to find all the lastnames that have five Chrs..and not use lengthy instr functions to optain the same result.

Objective 1: to find the position of the chr you are looking for. this can be any chr in a string but only works on the first Chr found.

objective 2 , to find the #chrs left of the search chr

Meaning of this code:
Table Fieldname = name
data lastname,firstname

Sql,james
jones,tom
long,how
craig,jenny
howard,mike
masters,shawn
smith,john

Sample SQL Statement
Sql statement used to optain the results
sSql = "SELECT * FROM data WHERE PATINDEX('%,%', name) -1 = 5"

The Sql function used is called PATINDEX
The sql statement used searched for the first , in the string

PATINDEX returns that the , is the 6th chr the - 1 moves back to the number of chrs found.
the result returns
jones,tom
craig,jenny
smith,john

This code actually does work if anyone enhances on this please let me know i would like to see other ways of getting the results to the right of the ,
again using an sql statement as above.

Thanks,
hostmaster@wantednow.com
www.wantednow.com

blog comments powered by Disqus
ASP CODE ARTICLES

- ASP Forms
- ASP: The Beginning
- Getting Remote Files With ASP Continued
- Inbox and Outbox Manipulation in ASP
- Relational DropDownList Using VB.NET
- Ad Tracking URL Hits
- Use ViewState to display one record per page...
- Send Email using ASP.NET formatted in HTML
- ASP File Explorer
- ASP/XML Interview questions by Srivatsan Sri...
- Pressing RETURN won't submit the form
- This shows how you get the TEXT of a combo r...
- Group Data by Adrian Forbes
- Multiple checkbox select sample
- Multiple checkbox select with all values sam...

ASP Web Hosting ASP.Net Web Hosting Windows Web Hosting
 
 
 

ASP Free Forums 
 RSS  Tutorials RSS
 RSS  Forums RSS
 RSS  All Feeds
Site Map 
Request Media Kit
Write For Us Get Paid 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Privacy Policy 
Support 


© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 4 - Follow our Sitemap
Most Popular Topics
All ASP.Net Tutorials