Parse a substring of characters to the left of a period

I am trying parse a substring of characters to the left of a period. I need to perfom a select statement that will parse a substring of data to the left of a period. The sql statement is:
SELECT     dbo.OrderHeader.PrimaryCustomerID, dbo.OrderHeader.OrderNumber, dbo.OrderLine.EventDateToDeliver, dbo.LineDetail.Weight,
                      dbo.OrderHeader.Remarks
FROM         dbo.OrderHeader INNER JOIN
                      dbo.OrderLine ON dbo.OrderHeader.ID = dbo.OrderLine.OrderHeaderID INNER JOIN
                      dbo.LineDetail ON dbo.OrderLine.ID = dbo.LineDetail.OrderLineID
where dbo.LineDetail.PO = '929477'

The output is:
PrimaryCustomerID    OrderNumber                     EventDateToDeliver             Weight       Remarks
102                          6061 - EXP 2.1014074546      2004-10-19 21:00:00.000          96.0        NULL
102                          6061 - EXP 2.1014074546      2004-10-19 21:00:00.000          148.0       NULL

The field that I need to parse is OrderNumber. The only thing that is constant is the period.
infutechAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Scott PletcherSenior DBACommented:
For the chars before the '.':

SELECT ..., LEFT(OrderNumber, CHARINDEX('.', OrderNumber) - 1)


For the chars after the '.':

SELECT ..., SUBSTRING(OrderNumber, CHARINDEX('.', OrderNumber) + 1, LEN(OrderNumber))


0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MikeWalshCommented:
When you say parse, do you mean parse or do you mean crop? Are you trying to only return what is to the left of the period or what is to the right of the period?

show an example of a row you would like returned.
0
sigmaconCommented:
this also makes sure that it works if there is not . - if that can never happen, just do:


(
        case when charindex('.', dbo.OrderHeader.OrderNumber) > 0
                then Left(dbo.OrderHeader.OrderNumber, charindex('.', dbo.OrderHeader.OrderNumber) - 1)
                else null
          end
    ) as ORDERBNUMBERLEFT


0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

MikeWalshCommented:
or nevermind, I could have given you both like scott did :)
0
pique_techCommented:
What part of the OrderNumber do you need to keep or process?  What you're asking isn't difficult, but can't be specifically addressed without better understanding what you need to parse and process.
0
sigmaconCommented:
or this if you want the order number when there is no period

(
        case when charindex('.', dbo.OrderHeader.OrderNumber) > 0
                then Left(dbo.OrderHeader.OrderNumber, charindex('.', dbo.OrderHeader.OrderNumber) - 1)
                else dbo.OrderHeader.OrderNumber
          end
    ) as ORDERBNUMBERLEFT

0
infutechAuthor Commented:
In my example above the Ordernumber is:  6061 - EXP 2.1014074546  I only need: 6061 - EXP 2  Retruned to me.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.