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 |
|
abhit_kumar
Posting Yak Master
147 Posts |
Posted - 2010-06-01 : 03:22:32
|
| HiIn a sql I want to extract characters from a string . For ex (1234-abc) . I want the result 1234 . I want to extract characters before -.Suppose the no is like 1119-asd then it should give 1119when 234roy = 234 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-06-01 : 03:40:16
|
select left(YourColumn,patindex('%[^0-9]%',YourColumn)-1) No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
Sachin.Nand
2937 Posts |
Posted - 2010-06-01 : 03:45:39
|
| How many occurrences of "-" will be present in the string?If just 1 then only the below will work else ignore it.SELECT parsename(replace('1234-abc','-','.'), 2)PBUH |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-06-01 : 03:46:11
|
Idera see OP's example in the last row:when 234roy = 234 No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
Sachin.Nand
2937 Posts |
Posted - 2010-06-01 : 03:55:26
|
quote: Originally posted by webfred Idera see OP's example in the last row:when 234roy = 234 No, you're never too old to Yak'n'Roll if you're too young to die.
Oh sorry.Another classic example of my bad habit of not reading the complete post. So I guess what the OP wants is getting numeric value from an alphanumeric string.PBUH |
 |
|
|
|
|
|