sql server - Sql query to convert nvarchar to int -


i have query total amount of column using aggregate function. column data type nvarchar(max). how can convert integer?

i have tried this:

  select sum(cast(amount int)),          branch      tblproducts      id = 4 group branch 

...but i'm getting:

conversion failed when converting nvarchar value '3600.00' data type int.

3600.00 not integer cast via float first

sum(cast(cast(amount float) int)) 

edit:

why float?

  • no idea of precision or scale across rows: float lesser evil perhaps
  • empty string cast 0 float, fails on decimal
  • float accepts stuff 5e-02, fails on decimal

Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -