Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
cplusplus
Aged Yak Warrior
567 Posts |
Posted - 2014-04-15 : 16:50:26
|
I have address table glfac column.select glfac from address;want to get all values before hyphen from left.900-SAN DIEGO CLINIC1-BAY CARE Hospitalwant to get 9001Thanks a lot for the helpful info. |
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2014-04-15 : 16:55:05
|
See this example:DECLARE @x VARCHAR(32) = '900-SAN DIEGO CLINIC';SELECT LEFT(@x,CHARINDEX('-',@x+'-')-1); |
|
|
MuralikrishnaVeera
Posting Yak Master
129 Posts |
Posted - 2014-04-17 : 02:29:40
|
[code]DECLARE @Temp VARCHAR(MAX)= '1000-SAN DIEGO CLINIC'Method 1 : SELECT LEFT(@Temp,CHARINDEX('-',@Temp)-1)Method 2 : SELECT SUBSTRING(@Temp,0,CHARINDEX('-',@Temp))[/code]---------------Murali KrishnaYou live only once ..If you do it right once is enough....... |
|
|
|
|
|