Convert a NUMERIC Data Column to VARCHAR when it is Null

Bobby P 221 Reputation points

So I have a NUMERIC field and if it is NULL I want to actually pass back the value '<NULL>'. This is for a user with a before and after image of data columns.

I tried ISNULL with CONVERT but I cannot seem to get the syntax down.

Can anyone please help me out with the syntax?

Thanks for your review and am hopeful for a reply.

A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,596 questions
{count} votes

2 answers

Sort by: Most helpful
  1. LiHong-MSFT 10,046 Reputation points

    Hi @Bobby P

    I tried ISNULL with CONVERT but I cannot seem to get the syntax down.

    When converting from Numeric to Varchar without specify the length,an error will return when the result length is too long to display.
    Did you try ISNULL(CONVERT(VARCHAR(50),NUMERIC_Field),'<NULL>') ? If it doesn't work, try replacing '50' with 'max'.

    Best regards,

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  2. Tom Phillips 17,721 Reputation points

    Just to be clear.

    A SELECT statement cannot return 2 different data types for the same column. Every record must conform to the same data type for the column. It is either NUMERIC or VARCHAR, it cannot be sometimes VARCHAR.

    0 comments No comments