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 2012 Forums
 Transact-SQL (2012)
 . at the end of the column

Author  Topic 

misterraj
Yak Posting Veteran

94 Posts

Posted - 2014-10-08 : 12:35:07
for a particular column in a table i want to update the column with the following condition:

if it doesnot contains a '.' at the end of the word i should add a . to it, if it contains i should not.

Please help me with a SQL Query.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2014-10-08 : 12:58:47
DECLARE @s varchar(200)

SET @s = 'some text without period'
SELECT CASE WHEN CHARINDEX('.', @s) = 0 THEN @s + '.' ELSE @s END

SET @s = 'some text without a period at the end'
SELECT CASE WHEN CHARINDEX('.', @s) = 0 THEN @s + '.' ELSE @s END

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

misterraj
Yak Posting Veteran

94 Posts

Posted - 2014-10-08 : 23:56:49
cant i do with a single query, because i have 1000's of records. All i have to check for a particular column in the record and do this logic for all 1000's of records.

one more thing, the column can have a sentence. I should only check for the . at the end. if its in the middle it should be ignored.

pls help
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2014-10-09 : 00:08:47
[code]
UPDATE yourtable
SET yourcolumn = yourcolumn + '.'
WHERE RIGHT(yourcolumn , 1) <> '.'
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

misterraj
Yak Posting Veteran

94 Posts

Posted - 2014-10-09 : 11:19:11
thanks khtan. it worked superb. simple and elegant
Go to Top of Page
   

- Advertisement -