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. Database & SysAdmin
  3. Database
  4. Stored Proc help

Stored Proc help

Scheduled Pinned Locked Moved Database
databasehelpquestion
3 Posts 3 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.
  • T Offline
    T Offline
    tthellebuyck
    wrote on last edited by
    #1

    I need some help writing a stored proc. First, I am inserting a range of ZipCodes into a db, ZipBegin and ZipEnd(12345-12346). Although that seems relatively simple, however, I need to check those ranges and make sure that there is no other over lapping range. for more clarity: range A 12345-12346 is in the db range B 12344-12347 is being inserted. as you can see these ranges overlap, if that occurs I need to use a raiserror and rollback the transaction. Does anyone have any suggestions on how I could do that?

    A J 2 Replies Last reply
    0
    • T tthellebuyck

      I need some help writing a stored proc. First, I am inserting a range of ZipCodes into a db, ZipBegin and ZipEnd(12345-12346). Although that seems relatively simple, however, I need to check those ranges and make sure that there is no other over lapping range. for more clarity: range A 12345-12346 is in the db range B 12344-12347 is being inserted. as you can see these ranges overlap, if that occurs I need to use a raiserror and rollback the transaction. Does anyone have any suggestions on how I could do that?

      A Offline
      A Offline
      andyharman
      wrote on last edited by
      #2

      What was wrong with my previous answer[^] to your question?

      1 Reply Last reply
      0
      • T tthellebuyck

        I need some help writing a stored proc. First, I am inserting a range of ZipCodes into a db, ZipBegin and ZipEnd(12345-12346). Although that seems relatively simple, however, I need to check those ranges and make sure that there is no other over lapping range. for more clarity: range A 12345-12346 is in the db range B 12344-12347 is being inserted. as you can see these ranges overlap, if that occurs I need to use a raiserror and rollback the transaction. Does anyone have any suggestions on how I could do that?

        J Offline
        J Offline
        John ph
        wrote on last edited by
        #3

        You want to check before or after inserting? below logic will help you. Before Inserting ------------------ check whether there is any ZIPCode exist within the range sql --- Select @begin = count(ZIPBegin) from tblZIPCodes where ZIPBegin between 12345 and 12346 Select @end = count(ZIPEnd) from tblZIPCodes where ZIPEnd between 12345 and 12346 If @begin > 0 or @end > 0 -- then there is an entry within that range already exist else --perform the insertion After Inserting ---------------- BEGIN TRANSACTION --Insert the records -- then use the same sql stmt written above to get the value of @begin and --@end If @begin > 1 or @end > 1 -- multiple entries has been made ROLLBACK TRANSACTION RAISERROR RETURN else --perform the insertion COMMIT TRANSACTION


        Regards
        John


        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