• Let's go step by step.

    CREATE TABLE #TEST(A varchar,B varchar(30)); ---> Field named A is of size 1 with type Varchar.

    ISNULL(A,B) ---> means:evaluate the field A, (the first parameter), if has something other than a NULL then return it to me otherwise return me the value converted to Varchar size 1 (As A is Varchar (1)) from varchar size 30 in field B for current record.

    So if you run

    SELECT A, B, ISNULL(A,B),LEN(ISNULL(A,B)) FROM #Test

    A B

    ---- ------------------------------ ---- -----------

    A NULL A 1

    NULL Some text S 1

    B NULL B 1

    NULL Some more text S 1

    so if you now run

    SELECT COUNT(*),LEN(ISNULL(A,B))

    FROM #TEST

    GROUP BY LEN(ISNULL(A,B));

    you'll see

    ----------- -----------

    4 1

    And

    SELECT A, B, ISNULL(B,A),LEN(ISNULL(B,A)) FROM #Test

    A B

    ---- ------------------------------ ------------------------------ -----------

    A NULL A 1

    NULL Some text Some text 9

    B NULL B 1

    NULL Some more text Some more text 14

    and run

    SELECT COUNT(*),LEN(ISNULL(B,A))

    FROM #TEST

    GROUP BY LEN(ISNULL(B,A));

    ----------- -----------

    2 1

    1 9

    1 14

    Now let's talk about COALESCE(A,B)

    COALESCE returns the first non-null expression among its arguments,

    If you run

    SELECT LEN(COALESCE(A,B)),COALESCE(A,B)

    FROM #TEST

    then

    ----------- ------------------------------

    1 A

    9 Some text

    1 B

    14 Some more text

    so

    SELECT COUNT(*),LEN(COALESCE(A,B))

    FROM #TEST

    GROUP BY LEN(COALESCE(A,B));

    ----------- -----------

    2 1

    1 9

    1 14

    .

    I hope this has been useful.

    Abdul Rehman