@@RowCOunt with Temp Table

  • I have a temp table I am deleting from. I want to verify the deletion by getting @@RowCount. However the value being returned is 0.

    I confirmed the deletion occured by a select statment right after the deletion.

    Can this be done like this?

    Delete #Import Where Col1 = @FileName

    SET @RowCount = @@RowCount --Returns 0

    select * From #Import --No Rows Returned b/c delete was successful

  • I just tried this:

    ID int identity primary key,

    Col1 char(1));

    insert into #T (Col1)

    select 'a' union all

    select 'b';

    set @RowCount = @@rowcount;

    select @RowCount;

    delete from #T

    where Col1 = 'b';

    set @RowCount = @@rowcount;

    select @rowcount;

    select *

    from #T;

    It gave correct numbers each time. I'm using SQL 2005, and don't readily have access to 2000, so can't test that script in that engine. Try running my script, see what you get.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • Thanks for the reply I just realized I was looking at the wrong temp table (which had no data at that point in the query)... doh! I thought maybe it was a limitation of temp tables.

  • That makes sense then.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

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

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