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 |
|
nobby
Yak Posting Veteran
58 Posts |
Posted - 2007-03-21 : 21:23:01
|
| I am trying to find a way to find a certian character in a string and then select everything after that character.for example i would look for the position of the underscore and then need to return everthing after it so in this case yes_noi would return no |
|
|
nobby
Yak Posting Veteran
58 Posts |
Posted - 2007-03-21 : 21:37:35
|
| i have managed to work out to use thisSUBSTRING(MyField, 4, 10)but how can i changed the 4 to a dynamic number found by finding the position of the underscore |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-03-21 : 21:41:05
|
[code]declare @str varchar(10)select @str = 'yes_no'select right(@str, len(@str) - charindex('_', @str))[/code] KH |
 |
|
|
nobby
Yak Posting Veteran
58 Posts |
Posted - 2007-03-21 : 21:48:26
|
| I have managed to do it this way can you see any problems with this waySELECT SUBSTRING(MyField, CHARINDEX('_', MyField) + 1, 20) AS Expr1FROM dbo.MyTable |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-03-21 : 21:58:00
|
yes the 20. You are assuming the max number of char after the '_' is 20.SELECT SUBSTRING(MyField, CHARINDEX('_', MyField) + 1, 20 len(MyField)) AS Expr1FROM dbo.MyTable KH |
 |
|
|
nobby
Yak Posting Veteran
58 Posts |
Posted - 2007-03-21 : 22:49:33
|
| Thanxs khtani have made that last change Thanxs for the help |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-03-22 : 01:30:39
|
| 8000 is fine too.Peter LarssonHelsingborg, Sweden |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-03-22 : 01:33:18
|
8000 is fine too if you are using SQL Server 2000  KH |
 |
|
|
|
|
|
|
|