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 2000 Forums
 Transact-SQL (2000)
 AVG CAST FLOAT

Author  Topic 

panzerschrank123
Starting Member

2 Posts

Posted - 2009-08-18 : 05:04:13
Hello members,
please can help me.

One colum of my database has some varchar numbers like: 35,95 or 34,99 or 99,99 and so on.
Now I want to make a statement like

select avg(replace(cast([mycolum] as float)),',','.') from [mytable] (nolock) where [mycolum] > '0,00'

But it doesn't work Pleas help me!

Thanks a lot

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-08-18 : 05:25:46
Do the replace before casting...



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-08-18 : 05:26:45
try like this
declare @tab table(val varchar(32))
insert into @tab select '35,95'
insert into @tab select '34,99'
insert into @tab select '99,99'

select avg(cast(replace(val,',','.')as float)) from @tab
Go to Top of Page

panzerschrank123
Starting Member

2 Posts

Posted - 2009-08-18 : 06:08:03
Hello Friends,

It works like

SELECT avg(cast(replace([myColum],',','.')as float))

from [mytable] (nolock)

where [myColum] >'0'

Thanks a lot !


Go to Top of Page
   

- Advertisement -