• Minnu (12/3/2012)


    Hi Team,

    BEGIN

    SELECT RTRIM(

    +ISNULL(Col_Name,'')+' : '

    +ISNULL(+CAST(ColB AS VARCHAR(10))+' ','')

    +ISNULL(' ColC :'+CAST(ColC AS VARCHAR(10))+' ','')

    ) FROM table_name

    END

    --

    if ColB is NULL then ColC should not append .

    Please help....

    If I understand you correctly you just need to add a case in here. (note I also added some spacing so it is more legible)

    SELECT RTRIM(

    + ISNULL(Col_Name, '') + ' : '

    + ISNULL(CAST(ColB AS VARCHAR(10)) + ' ', '')

    + case when ColB IS NULL then NULL else ISNULL(' ColC :' + CAST(ColC AS VARCHAR(10)) + ' ', '') end

    ) FROM table_name

    _______________________________________________________________

    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/