Replace empty values as 0 instead of null while joining two tables in sql

I have join two tables t1 and t2. The output produces some null records since there is no data in the table t2. Instead of showing null I want to show 0 since I have to perform some arithmetic operation in the crystal reports.
please help me…..

  • Is there any way to find dependents of the column in SQL Server?
  • SQL To Find Word Pairs/Clusters Between Columns
  • How to SELECT * but without “Column names must be unique in each view”
  • Handling multiple rows in SQL Server trigger
  • Creating a Non Clustered Index with a DateTime column as key
  • SQL Grouping and table values
  • 2 Solutions collect form web for “Replace empty values as 0 instead of null while joining two tables in sql”

    sample example

    declare @t table (ID int)
    declare @t1 table (ID int)
    
    insert into @t (id) values (1)
    
    select t.ID,ISNULL(TT.ID,0)id  from @t t
    LEFT JOIN @t1 tt
    ON t.ID = tt.ID 
    

    Use the COALESCE function which automatically replace null values as 0.
    Sample

    SELECT COALESCE(total_amount, 0) from #Temp1
    
    MS SQL Server is a Microsoft SQL Database product, include sql server standard, sql server management studio, sql server express and so on.