Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trucate text value in Select statement

Status
Not open for further replies.

jase2006

Technical User
Nov 17, 2006
53
0
0
GB
Is there a way to only extract part of the values from a column in a Select statement? e.g. "Name" field contain value "JOHN GRANT" and I only want to extract the first 4 characters "JOHN". Any suggestions?
 
This will differ from database to database.

You will want to look into the SUBSTRING function for your particular database.

Here are some options for how to get the position of the space (which you will need to know how many characters to take with SUBSTRING):

SQL Server: CHARINDEX, PATINDEX
MS Access: INSTR
ANSI-SQL Equivalent: POSITION

Hope this helps,

Alex

[small]----signature below----[/small]
I don't do any programming whatsoever

Ignorance of certain subjects is a great part of wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top