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

Remove parts of a varchar field 1

Status
Not open for further replies.

akalinowski

IS-IT--Management
Oct 3, 2006
190
US
I have a table where styles are setup as a number dash size dash color as a single column
i need to get the style out but its not a constant length
is there a way i can cut all data after teh 1st dash
example of the data is

ST123-S-BK
SD23-M-BL
23RDSDFD-M-RD

thanks!

akalinowski
 
You can use the CharIndex function to locate the dash and then use that in the LEFT function to get the data to the left of the first dash. Like this:

Code:
Select Left(YourColumnNameHere, CharIndex('-', YourColumnNameHere+ '-') -1)

-George
Microsoft SQL Server MVP
My Blogs
SQLCop
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top