Print Statement Into a Temp Table

  • Any ideas how can take the results of the following statement and insert it into a temp table:

    PRINT

    LTRIM(STR(@@ROWCOUNT))+' disposition records inserted.'

    For example the row would contain '1444 Disposition records inserted.'

    I created a temp table as follows:

    CREATE TABLE #Log (messagecount VARACHAR (100)) and now I need to insert into it.

     

    Thanks,

    Art

  • declare

    @msg varchar(100)

    set

    @msg = LTRIM(STR(@@ROWCOUNT))+' disposition records inserted.'

    insert

    into #Log values (@msg)

     

    --james

  • Ummmm, why can't you just use a simple insert statement????

    INSERT INTO #Log (MessageCount)

    SELECT LTRIM(STR(@@ROWCOUNT))+' disposition records inserted.'

    --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)

  • I took Jeff idea and ran with it. Its working fine now.

     

    Thanks for all the input.

  • Hmm, I guess that works too. 

  • Arthur,

    The only thing that you have to remember is that if anything comes between the statement that creates the row count and the insert, then you'll need to use James' method because @@ROWCOUNT contains the rowcount of whatever the last statement before it's use was.

    James,

    Heh, that wasn't directed at you... you just posted before I did so it looks that way...

    --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)

  • Jeff: No problem, it actually applied to me too, when I saw your post it was a "Duh! why didn't I think of that" moment  

    James.

Viewing 7 posts - 1 through 6 (of 6 total)

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