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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Way of trimming results in SQL???

Status
Not open for further replies.

BobLoblaws

Programmer
Nov 20, 2001
149
CA
Let's say you have a simple SELECT statement that returns maybe 10 records.
SELECT Name from TableName WHERE Name LIKE 's*';

All the records I want are prefixed with the letter 's', but I want the results to display without the 's'. However, the 's' is necessary to be prefixed. Is there a way to remove it in the SELECT statement? Something similar to a Trim() in VB.

If this doesn't make sense then nevermind.
 
Try this:

Select mid(Tablename.name,2,len(tablename.name) - 1)
From Tablename
Where Name LIKE 's*';
 

The 3ed parameter isn't required for the MID function. Therefore, the query can be simplified as follows.

Select Mid([Name],2)
From Tablename
Where Left([Name],1)="s"

NOTE: Use of Left([Name],1) is an alternate to Like "s*". The result should be the same. Terry L. Broadbent
FAQ183-874 contains tips for posting questions in these forums.
NOTE: Reference to the FAQ is not directed at any individual.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top