• asranantha (10/18/2013)


    Hi friends i have small doubt in sql server how to handled nulls and empty values and replac other values in sql server

    table data look like below

    table :emp

    id ,name ,sal ,deptno

    1 ,abc ,1oo ,10

    2 ,venu ,2000 ,null

    3 ,null , ,20

    4 ,balu ,null ,

    5 ,hari , ,30

    based on above table i want output like below

    id , name ,sal ,deptno

    1 , abc ,100 ,10

    2 , venu ,2000 ,NA

    3 , NA , NA ,20

    4 , balu ,NA ,NA

    5 , hari ,NA ,30

    plese tell me how to write query while achive in above issuse.

    This is a little odd given the data you presented. Here are a couple of ways you do it.

    select isnull(nullif('', YourColumn), 'NA') as YourColumn,

    case when YourColumn IS NULL OR YourColumn = '' then 'NA' else YourColumn end as YourColumn

    Here is the problem. The data you posted appears to be ints. You can't mix int and varchar data in the same column unless you cast your numeric data to a varchar. If at all possible I would do this type of formatting in the front end instead of in sql.

    _______________________________________________________________

    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/