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 |
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 ENDSET @s = 'some text without a period at the end'SELECT CASE WHEN CHARINDEX('.', @s) = 0 THEN @s + '.' ELSE @s ENDTara KizerSQL Server MVP since 2007http://weblogs.sqlteam.com/tarad/ |
|
|
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 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2014-10-09 : 00:08:47
|
[code]UPDATE yourtableSET yourcolumn = yourcolumn + '.'WHERE RIGHT(yourcolumn , 1) <> '.'[/code] KH[spoiler]Time is always against us[/spoiler] |
|
|
misterraj
Yak Posting Veteran
94 Posts |
Posted - 2014-10-09 : 11:19:11
|
thanks khtan. it worked superb. simple and elegant |
|
|
|
|
|