Function max E Cast JUnta Sql Server 2008 R2

0

I need to convert a field from Nvarchar to Float in a search, and get the highest value.

This function works

SELECT MAX(valor) 
from [Enops].[dbo].[Tbl_Pulsomedia15_Vazao_Eta_B_Bentes]
Where valor <> 'processando'  and valor <> 'Perda de Sinal'.

But when I put the max, it says that it is not a function of the sql server

SELECT Max (cast(valor as nvarchar(200))AS FloatValue) 
from[Enops].[dbo].[Tbl_Pulsomedia15_Vazao_Eta_B_Bentes] 

Would you have any way to do this?

    
asked by anonymous 17.01.2018 / 11:58

1 answer

0

resolved

SELECT MAX(cast(replace(convert(varchar,ltrim(rtrim(valor))),',','.') as float)) AS Maximo, 
       MIN(cast(replace(convert(varchar,ltrim(rtrim(valor))),',','.') as float)) AS Mínimo 
From [Enops].[dbo].[Tbl_Pulsomedia15_Vazao_Eta_B_Bentes] 
Where valor <> 'processando'  and valor <> 'Perda de Sinal'
    
17.01.2018 / 12:51