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 |
memarcie
Yak Posting Veteran
91 Posts |
Posted - 2007-12-04 : 09:05:56
|
I have a text field and I want to get the data in the field after a certain character. For example the column contains:20070814~HCP*02*32*19.75*HEOS~LX*2~SV1*HC:97014:59*35.75*I want to get what follows the characters 'HC', they will not always be in the same position in the field. Can you tell me if this is possible and what I search on to find more info?Thanks,Marcie |
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2007-12-04 : 09:11:57
|
select right(str, charindex('*HC:',str)+4,len(Str))or maybeselect left(right(str, charindex('*HC:',str)+4,len(Str)), charindex('*',right(str, charindex('*HC:',str)+4,len(Str))-1)==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
memarcie
Yak Posting Veteran
91 Posts |
Posted - 2007-12-04 : 09:49:28
|
The right function does not work with a data type of text. Any other ideas? Thanks |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-12-04 : 10:18:23
|
[code]DECLARE @Sample TABLE (Col1 TEXT)INSERT @SampleSELECT '20070814~HCP*02*32*19.75*HEOS~LX*2~SV1*HC:97014:59*35.75*'SELECT Col1, SUBSTRING(Col1, CHARINDEX('*HC:', Col1), 8000)FROM @Sample[/code] E 12°55'05.25"N 56°04'39.16" |
 |
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2007-12-04 : 10:56:54
|
how long is your string? If it might be longer than 8000 chars then you can't use charindex.select substring(str, patindex('%*HC:%',str)+4,8000)or maybeselect substring(substring(str, patindex('%*HC:%',str)+4,8000), charindex('*',substring(str, patindex('%*HC:%',str)+4,8000))-1)==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
|
|
|
|