Link to home
Start Free TrialLog in
Avatar of mike247
mike247Flag for United States of America

asked on

return data to left of dash excluding the dash

I have a database of inventory items that have prefixes based on manufacturers.  We want to compile a list of these prefixes.  I need to return only the data to the left of the first dash in the ItemNumber.  There could be items with no dash.  Any help you can provide is much appreciated.  Thanks,
Avatar of Mark Wills
Mark Wills
Flag of Australia image

Something like :
Select itemNumber, left(itemnumber,charindex('-',itemnumber) -1) as manufacturer
from yourtable

Open in new window


Some samples might make it easier :)
ASKER CERTIFIED SOLUTION
Avatar of Mark Wills
Mark Wills
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SELECT LEFT(ItemNumber, CHARINDEX('-', ItemNumber + '-') - 1) AS TrimmedItemNumber

FROM ...
G'day Scott,

Yeah, was thinking of that except it would return the entire itemnumber when all we need is the Manufacturer code - which may not exist. So, thought it best not to return the entire itemnumber where there is no manufacturer code / prefix...

Seem to recall a similar question about prefixes but in a trigger from Mike...

Just a thought......

Cheers,
Mark
Avatar of mike247

ASKER

Sorry, I thought I had closed this out the day the answer came in.  I guess I didn't click through all the "next" buttons.