Please start any new threads on our new site at http://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 how to get the value before hyphen from left side
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

cplusplus
Aged Yak Warrior

567 Posts

Posted - 04/15/2014 :  16:50:26  Show Profile  Reply with Quote
I have address table glfac column.

select glfac from address;

want to get all values before hyphen from left.

900-SAN DIEGO CLINIC
1-BAY CARE Hospital

want to get

900
1

Thanks a lot for the helpful info.

James K
Flowing Fount of Yak Knowledge

3873 Posts

Posted - 04/15/2014 :  16:55:05  Show Profile  Reply with Quote
See this example:
DECLARE @x VARCHAR(32) = '900-SAN DIEGO CLINIC';
SELECT LEFT(@x,CHARINDEX('-',@x+'-')-1);
Go to Top of Page

MuralikrishnaVeera
Posting Yak Master

India
128 Posts

Posted - 04/17/2014 :  02:29:40  Show Profile  Reply with Quote

DECLARE @Temp VARCHAR(MAX)= '1000-SAN DIEGO CLINIC'

Method 1 : SELECT LEFT(@Temp,CHARINDEX('-',@Temp)-1)

Method 2 : SELECT SUBSTRING(@Temp,0,CHARINDEX('-',@Temp))


---------------
Murali Krishna

You live only once ..If you do it right once is enough.......
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000