convert int to varchar and concatenate

  • Why does this return null?! How can I go around this problem? Thanks.

    @path is a varchar and I would like to add underscore + record id to the end of it.

    @path + '_' + cast (scope_identity() as varchar(10))

  • what does select @path return?

    If @path is null the string returned from the concatenation will be null if SET CONCAT_NULL_YIELDS_NULL in ON.

  • @path is not null! I pass a value to @path. I have tested it. The value is passed.

    procedure....

    @path

    ..

    begin

    insert into mytable ([[Path])

    values ( @path + '_' + cast (scope_identity() as varchar(10)) )

    .......

  • Then scope_identity is returning null. Tried this, select scope_identity(), on my dev server, and it returned null.

    I'd put an isnull() with a default value around your call to scope_identity and see it that is what is happening.

  • Scope_Identity() will be null until you actually do an INSERT.

    --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)
    Intro to Tally Tables and Functions

Viewing 5 posts - 1 through 4 (of 4 total)

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