SQL Server Forums
Profile | Register | 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
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

cplusplus
Aged Yak Warrior

534 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

3573 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
106 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  
 New 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.05 seconds. Powered By: Snitz Forums 2000