double split - splitting a string by more than one delimiter

Each line of data below is stored in a single nvarchar field.

CUSTOM,FedEx by Monday Afternoon (11th),18,0
CUSTOM,Standard US Mail,6.5,0
CUSTOM,US Priority Mail + Delivery Conf.,7.25,0
CUSTOM,FedEx by Thursday Morning (21st),35,0
CUSTOM,FedEx by Wednesday Morning (6th),35,0
CUSTOM,FedEx by Friday Afternoon (8th),18,0
CUSTOM,FedEx by Thursday Afternoon (7th),18,0
CUSTOM,FedEx by Friday Afternoon (3rd),18,0
CUSTOM,FedEx by Wednesday Afternoon (6th),30,0
USPS,USPS Airmail Letter Post ,7.55,0
CUSTOM,UPS Ground,12,0

I am creating a view in SQL Server 2000 where I need the data above displayed as below.

FedEx by Monday Afternoon
Standard US Mail
US Priority Mail + Delivery Conf.
FedEx by Thursday Morning
FedEx by Wednesday Morning
FedEx by Friday Afternoon
FedEx by Thursday Afternoon
FedEx by Friday Afternoon
FedEx by Wednesday Afternoon
USPS Airmail Letter Post
UPS Ground

Please Note that data after '(' is always discarded.

Please let me know what syntax will achive my goal.  

Thank You.
bbramanAsked:
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.

Anthony PerkinsCommented:
Try something like this (although it might be better accomplished in a UDF):

Select      SUBSTRING(@YourColumnName, CHARINDEX(',', @YourColumnName) + 1, CHARINDEX('(', @YourColumnName) - CHARINDEX(',', @YourColumnName) - 1)
Anthony PerkinsCommented:
Here is the complete syntax:
Select      SUBSTRING(YourColumnName, CHARINDEX(',', YourColumnName) + 1, CHARINDEX('(', YourColumnName) - CHARINDEX(',', YourColumnName) - 1)
From      YourTableName
bbramanAuthor Commented:
Thank you for your attention to my question.

The complete syntax you provided returned an 'invalid length parameter passed to the substring function" message.
Learn SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

Anthony PerkinsCommented:
That is because not all of the columns have "(".  You have a couple of options:
1. Enhance that query to allow for the possibility of no "(" or
2. Create a function (UDF) to accomplish the same.  The advantage here is that it is easier to maintain.

Let me know what is your poison.

Anthony PerkinsCommented:
Here is the UDF solution:

Create Function udf_GetValue(@Value varchar(100))

Returns varchar(100)

As

Begin

Declare @Pos tinyint
Set @Pos = CHARINDEX(',', @Value)

If @Pos > 0
   Begin
      Set @Value = SUBSTRING(@Value, @Pos + 1, 100)
      Set @Pos = CHARINDEX('(', @Value)
      If @Pos > 0
         Begin
            Set @Value = LEFT(@Value, @Pos - 1)
         End
   End

Return @Value

End

You would then call it as follows:

Select     dbo.udf_GetValue(YourColumnName)
From     YourTableName
bbramanAuthor Commented:
The UDF approach is fine, but the function does not have the right results:

FedEx by Monday Afternoon
Standard US Mail,6.5,0
US Priority Mail + Delivery Conf.,7.25,0
FedEx by Thursday Morning
FedEx by Wednesday Morning
FedEx by Friday Afternoon
FedEx by Thursday Afternoon
FedEx by Friday Afternoon
FedEx by Wednesday Afternoon
USPS Airmail Letter Post ,7.55,0
UPS Ground,12,0

Still do not match what I am looking for, see below:

FedEx by Monday Afternoon
Standard US Mail
US Priority Mail + Delivery Conf.
FedEx by Thursday Morning
FedEx by Wednesday Morning
FedEx by Friday Afternoon
FedEx by Thursday Afternoon
FedEx by Friday Afternoon
FedEx by Wednesday Afternoon
USPS Airmail Letter Post
UPS Ground

Thank you for your attention to my question.
Anthony PerkinsCommented:
Ok.  Make the following change:
CREATE Function udf_GetValue(@Value varchar(100))

Returns varchar(100)

As

Begin

Declare @Pos tinyint
Set @Pos = CHARINDEX(',', @Value)

If @Pos > 0
   Begin
      Set @Value = SUBSTRING(@Value, @Pos + 1, 100)
      Set @Pos = CHARINDEX(',', @Value)
      If @Pos > 0
         Begin
            Set @Value = LEFT(@Value, @Pos - 1)
         End
      Set @Pos = CHARINDEX('(', @Value)
      If @Pos > 0
         Begin
            Set @Value = LEFT(@Value, @Pos - 1)
         End
   End

Return @Value

End


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
bbramanAuthor Commented:
That did it, Thank You.
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.