Home > database >  The conversion of the string
The conversion of the string

Time:11-12

Some fields in the table is varchar (128), the remaining value (value, NULL, ' ') to the value is NULL and 'into the number 0
How to write SQL
Sql08R2 version

Had better not use case when such fields in the table because of the many, case number limitation when nested

Logic is such, but this wrong
Select the convert (float, isnull ((isnull (d_var1, ' ')=' '), 0)) + the convert (float, isnull ((isnull (d_var2, ' ')=' '), 0))...

CodePudding user response:

Please provide the table structure, test data, processing logic and want results.

CodePudding user response:

D_var1 d_var2
12.8 null
10.9 ""
"" 3.62
Null 7.2
"" ""
Null null
5.3 4.7

CodePudding user response:

The Select d_var1 + d_var2
"And null to 0

Two columns are varchar (128).

CodePudding user response:

SELECT the IIF (ISNULL (d_var1, ' ')=', 0, CONVERT (FLOAT, d_var1)) + IIF (ISNULL (d_var2, ' ')=', 0, CONVERT (FLOAT, d_var2))
  • Related