Error converting data type varchar to numeric.

  • , a.sku + p1.SHORT_DESC + ' ' + p1.LONG_DESC1 AS short_description

    sku is numeric

    the descriptions are nvarchar

    It works until I add the sku to the front then I get Error converting data type varchar to numeric.

    Any help is appreciated.

  • Explicitly convert the SKU to something like a VARCHAR(10) using CAST or CONVERT.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Use CONCAT instead of the plus sign - CONCAT will take care of converting to the appropriate data type for you.

    , CONCAT(a.sku, p1.SHORT_DESC, ' ', p1.LONG_DESC1) AS short_description

    Declare @sku int = 1234
    , @short_desc varchar(20) = 'short'
    , @long_desc1 varchar(100) = 'this is the long one';

    Select concat(@sku, '-', @short_desc, '-', @long_desc1);

     

    Jeffrey Williams
    “We are all faced with a series of great opportunities brilliantly disguised as impossible situations.”

    ― Charles R. Swindoll

    How to post questions to get better answers faster
    Managing Transaction Logs

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply