Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Truncate the recordset text

Status
Not open for further replies.

damipera

Technical User
Dec 1, 2005
134
GB
hi guys, can you please give me some suggestions how i could achieve this? thanks for any help.

myTable:
id - txtCol
1 - detailed financial information on Apple Inc. (NASDAQ:AAPL) including real-time
2 - View the latest Apple real-time stock quote information. Get detailed breaking investment performances

and i want to have the resulting recordset something like this when i search for the word 'Apple':
id - txtCol
1 - ... information on Apple Inc. (NASDAQ:AAPL) including...

2 - ... latest Apple real-time...
 
Here is a basic example...

declare @test varchar(200)

set @test='View the latest Apple real-time stock quote information. Get detailed breaking investment performances'

--Explanation
--Find 'Apple' then a starting place 15 character before it.
--charindex('Apple',@test)-15

--then find the first space in that 15 characters
--select charindex(' ',@test,charindex('Apple',@test)-15)

--Put it all together.
select '... ' + substring(@test,charindex(' ',@test,charindex('Apple',@test)-15),50)

Simi

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top