SQL Replacing a Null value with 0 within a Pivot

Prosperity

I have this query,

Select * From 
(Select 
    S.EmployeeID As [Employee ID],
    E.Name,
    YEAR([Date]) As [Year],
    DATENAME(MONTH, [Date]) As [Month], 
    IsNull(SUM(Amount), 0) As TotalAmount
    From Sales S Left Outer Join Employee E
    On S.EmployeeID = E.EmployeeID
    Group By 
    S.EmployeeID,
    E.Name, 
    YEAR([Date]),
    DATENAME(MONTH, [Date])) As MonthlySale
Pivot(SUM(TotalAmount)   
    For Month In ([January],[February],[March],[April],[May],
                  [June],[July],[August],[September],[October],
                  [November],[December])) As MyPivot

Which returns this table (Example Table),

+--+---------+-----+------+-------+
|ID|  Name   |Year |Jan   |Feb    | Exc
+--+---------+-----+------+-------+
|1 |John Doe |2014 |Null  |Null   | Exc
+--+---------+-----+------+-------+
|2 |Jane Doe |2014 |Null  |Null   | Exc
+--+---------+-----+------+-------+

How can I change those null values to 0s, I tried IsNull but to no avial, any ideas?

Prosperity

Ended up using,

Select [Employee ID], Name, @Year As [Year],
IsNull(January, 0)  As January,  IsNull(February, 0)  As February,  IsNull(March, 0)      As March,
IsNull(April, 0)    As April,    IsNull(May, 0)       As May,       IsNull(June, 0)       As June,
IsNull(July, 0)     As July,     IsNull(August, 0)    As August,    IsNull(September, 0)  As September,
IsNull(October, 0)  As October,  IsNull(November, 0)  As November,  IsNull(December, 0)   As December
From 

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Returning "0" for NULL values within Dynamic Pivot for SQL Server

From Dev

Set Value With NULL When Pivot SQL Selection Return 0 Rows

From Java

Replacing NULL with 0 in a SQL server query

From Dev

Dynamic pivot null to 0

From Dev

How To Set NULL is 0 in SQL Dynamic Pivot Query

From Dev

Replacing a value with NULL in a table in SQL Server using vb.net

From Dev

Still getting NULL value for column in SQL pivot table

From Dev

Getting null value in the Grand Total column in the Pivot Table in sql

From Dev

Sql Server pivot columns into rows fill NULL with zero or existing value

From Dev

Second Pivot within SQL query

From Dev

Dynamic Pivot without Null value

From Dev

Dynamic Pivot without Null value

From Dev

SQL Server replacing apostrophes within php variables

From Dev

SQL Server replacing only abbreviation within a string

From Dev

Replacing multiple null value columns with blank in tableau

From Dev

Detecting null value and replacing string C#

From Dev

Replacing "(null)" with blank cell in SQL query result

From Dev

SQL Server replacing null with empty string

From Dev

SQL Server replacing null with empty string

From Dev

(SQL) Efficient way of replacing of NULL values in DataGridView?

From Dev

SQL server pivot query not taking null count

From Dev

SQL Server Pivot is inserting NULL values

From Dev

SQL case 0 then NULL

From Dev

SQL Server if Null = 0

From Dev

sql changing null to 0

From Dev

Replacing unwanted portions of a string value in SQL column

From Dev

Replacing null values with 0 after spark dataframe left outer join

From Dev

SQL separate columns by rows value (pivot)

From Dev

How to pivot all rows value using sql

Related Related

HotTag

Archive