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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Selecting First Sentence

Author  Topic 

uttam548
Starting Member

12 Posts

Posted - 2009-01-27 : 01:53:29
I need to SELECT the first sentence from a description field in a database table. Please suggest me how this can be done in SQL Server.
Thanks.

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-01-27 : 01:58:55
use left, substring functions
Go to Top of Page

Nageswar9
Aged Yak Warrior

600 Posts

Posted - 2009-01-27 : 02:02:46
Can u Post ur database table along with data
Go to Top of Page

Nageswar9
Aged Yak Warrior

600 Posts

Posted - 2009-01-27 : 02:08:43
for example take the below query,
declare @temp table ( val varchar(32))
insert into @temp
select 'India is my country'

select left(val,5) from @temp
(or)
select substring(val,1,charindex(' ',val,1)) from @temp
Go to Top of Page

uttam548
Starting Member

12 Posts

Posted - 2009-01-27 : 02:14:51
Thanks Nageswar9 for your reply. It returns first word of the text provided.
I solved my problem with this query.
"select left(description,CHARINDEX('.',description,0)) from news"
Go to Top of Page

Nageswar9
Aged Yak Warrior

600 Posts

Posted - 2009-01-27 : 02:17:32
quote:
Originally posted by uttam548

Thanks Nageswar9 for your reply. It returns first word of the text provided.
I solved my problem with this query.
"select left(description,CHARINDEX('.',description,0)) from news"




welcome
Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-01-27 : 02:27:32
hi uttam,
use like this too

select case when CHARINDEX('.',description,0) > 0 then substring(description,1,CHARINDEX('.',description,0))
else description end as col1
Go to Top of Page
   

- Advertisement -