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
 General SQL Server Forums
 New to SQL Server Programming
 conversion help

Author  Topic 

sent_sara
Constraint Violating Yak Guru

377 Posts

Posted - 2008-08-25 : 04:43:40
hi friends,can any 1 help 2 solve the below issue?

From the numeric value,
the logic need to be applied
is:
round of 2 from the decimal and
finally only 2 values need to come

Eg:
Text1 is of type varchar

select text1 from test1
Text1
**********
10.000000000
10.020000000
abcd

output should come as:
Text1
10.00
10.02
abcd

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-08-25 : 04:46:14
[code]
update t
set text1 = convert(varchar(20), convert(decimal(20,2), text1))
from yourtable t
where isnumeric(text1) = 1
[/code]


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

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-08-25 : 04:50:40
quote:
Originally posted by khtan


update t
set text1 = convert(varchar(20), convert(decimal(20,2), text1))
from yourtable t
where isnumeric(text1) = 1



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




Isnumeric() is not reliable
http://sqlblogcasts.com/blogs/madhivanan/archive/2007/08/27/enhanced-isnumeric-function.aspx

use

col not like '%[^.0-9]%'

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -