• if you execute the ready made query which is my first code block it will execute fine and after 2013-08-11 the recordscount values will null on the output.

    my requirement is i need to get the daysinlate from table company based on the name and check for the null columns and get the column value and add as days and display the value.

    I know i am little confused. as i said earlier after 2013-08-11 the recordscount values are null on the output of my query.

    Nice job posting ddl and sample data. Of course your columns are NULL after 8/11. You don't have any data after that "date".

    Can you explain what you want the output to be when there is no data to use?

    You might also consider using a cross tab instead of a pivot. I find it a lot easier to work with and often faster than a PIVOT. You could also leverage a tally table so you don't have to hard code a whole months worth of data.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/