Charles Baldo
asked on
Need SQL function to get part of sring
Hi
using Microsoft SQL Server 2005. I need a SQLfunction or statement to get part of a varchar.
All the values will have 2 dashes '-' like this:
AZ - District of Arizona - Phoenix
CA - Central District of California - San Fernando Valley
FL - Northern District of Florida - Tallahassee
I need to get everything to the left of the second dash without the space before it. So I would need
AZ - District of Arizona<no space>
CA - Central District of California
FL - Northern District of Florida
somewhat new I have no idea any help please
using Microsoft SQL Server 2005. I need a SQLfunction or statement to get part of a varchar.
All the values will have 2 dashes '-' like this:
AZ - District of Arizona - Phoenix
CA - Central District of California - San Fernando Valley
FL - Northern District of Florida - Tallahassee
I need to get everything to the left of the second dash without the space before it. So I would need
AZ - District of Arizona<no space>
CA - Central District of California
FL - Northern District of Florida
somewhat new I have no idea any help please
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks All
SELECT SUBSTRING(YourColumn, CHARINDEX('-', YourColumn) + 2, CHARINDEX('-', YourColumn, CHARINDEX('-', YourColumn) + 1) - CHARINDEX('-', YourColumn) - 2)
Greg