Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. FacePalm

FacePalm

Scheduled Pinned Locked Moved The Weird and The Wonderful
databasesharepointannouncement
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    So I have been working on a replicating database. Trigger on one of the tables being replicated, used to populate the Data Warehouse. So, trigger writes record to 'Ids that need to be updated in the DW' table and calls SP that reads through that table for all unprocessed records, and processes them. Because some related data may not (yet) have been replicated, this SP can legitimately fail to update the DW, and so shouldn't update the 'Ids that need to be updated in the DW' table to set it as processed. I"d been having a few problems with various bits and bobs, and had created a table, MaxxxsTemporaryTable, just used for logging stuff. So here was my code ...

    Insert into DW.SomeTable
    Select col, othercol, morecols
    From ReplicatedDatabaseTable join AllSortsOfOtherTables

    Insert into MaxxxsTemporaryTable Select @Id, @OtherId, @@ROWCOUNT

    IF @@RowCount > 0
    BEGIN
    Update 'Ids that need to be updated in the DW' table
    Set IsProcessed = 1
    Where Id = @Id
    END

    But, for some reason, the IsProcessed flag was always being set, even though I knew it was zero, because that was what was written in my temp table!! :-O I had to post about it to bluff my shame!

    PooperPig - Coming Soon

    B 1 Reply Last reply
    0
    • L Lost User

      So I have been working on a replicating database. Trigger on one of the tables being replicated, used to populate the Data Warehouse. So, trigger writes record to 'Ids that need to be updated in the DW' table and calls SP that reads through that table for all unprocessed records, and processes them. Because some related data may not (yet) have been replicated, this SP can legitimately fail to update the DW, and so shouldn't update the 'Ids that need to be updated in the DW' table to set it as processed. I"d been having a few problems with various bits and bobs, and had created a table, MaxxxsTemporaryTable, just used for logging stuff. So here was my code ...

      Insert into DW.SomeTable
      Select col, othercol, morecols
      From ReplicatedDatabaseTable join AllSortsOfOtherTables

      Insert into MaxxxsTemporaryTable Select @Id, @OtherId, @@ROWCOUNT

      IF @@RowCount > 0
      BEGIN
      Update 'Ids that need to be updated in the DW' table
      Set IsProcessed = 1
      Where Id = @Id
      END

      But, for some reason, the IsProcessed flag was always being set, even though I knew it was zero, because that was what was written in my temp table!! :-O I had to post about it to bluff my shame!

      PooperPig - Coming Soon

      B Offline
      B Offline
      Brisingr Aerowing
      wrote on last edited by
      #2

      I don't know anything about SQL, so what is the goof?

      What do you get when you cross a joke with a rhetorical question?

      L 1 Reply Last reply
      0
      • B Brisingr Aerowing

        I don't know anything about SQL, so what is the goof?

        What do you get when you cross a joke with a rhetorical question?

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        @@ROWCOUNT is a 'system variable' that tells you how many rows were affected by the last statement. So my Insert into the temporary table, changed it from whatever value it had (zero) , to 1 - so it was always > 0 so always set IsProcessed

        PooperPig - Coming Soon

        B 1 Reply Last reply
        0
        • L Lost User

          @@ROWCOUNT is a 'system variable' that tells you how many rows were affected by the last statement. So my Insert into the temporary table, changed it from whatever value it had (zero) , to 1 - so it was always > 0 so always set IsProcessed

          PooperPig - Coming Soon

          B Offline
          B Offline
          Brisingr Aerowing
          wrote on last edited by
          #4

          Ah. I see.

          What do you get when you cross a joke with a rhetorical question?

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups