Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding fields containing NULL + 0

Status
Not open for further replies.

Cheech

Technical User
Nov 6, 2000
2,933
EU
I am trying to add together 2 fields in a SELECT statement, either of the 2 options works below until the situation arises where one field is NULL and the other contains 0.00 all that is returned at this point is ".00" without the leading 0. Any ideas why or how to work round?

Code:
ISNULL(CONVERT(DECIMAL(10,2), replace(NIV,',','')), 0) + ISNULL(CONVERT(DECIMAL(10,2), replace([NIV(Indirects)],',','')), 0) as NIVTotal

ISNULL(CAST(replace(NIV,',','')AS DECIMAL(10,2)), 0) + ISNULL(CAST(replace([NIV(Indirects)],',','')AS DECIMAL(10,2)), 0) AS NIVTotal

Cheech

[Peace][Pipe]
 
FYI I solved this using
Code:
cast(CONVERT(DECIMAL(18,2), replace(ISNULL(NIV, 0.00),',','')) + CONVERT(DECIMAL(18,2), replace(ISNULL([NIV(Indirects)], 0.00),',','')) as nvarchar) as NIVTotal

[Peace][Pipe]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top