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. Return value from a stored procedure

Return value from a stored procedure

Scheduled Pinned Locked Moved Database
sharepointdatabasesalesquestion
4 Posts 3 Posters 1 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.
  • M Offline
    M Offline
    Member 4260270
    wrote on last edited by
    #1

    Hi, I have one stored procedure for inserting values to 5 tables at a time.So there are 5 insert statements in a single SP.Here some fields are common ie.there is customer address and sponsor address and all these addresses are stored in a single table.Firstly I insert customer details in the customer table and contact details to the contact table.Also sponsor contact addresses are stored in the contact table.How can I handle this Thanks Denny

    _ A 2 Replies Last reply
    0
    • M Member 4260270

      Hi, I have one stored procedure for inserting values to 5 tables at a time.So there are 5 insert statements in a single SP.Here some fields are common ie.there is customer address and sponsor address and all these addresses are stored in a single table.Firstly I insert customer details in the customer table and contact details to the contact table.Also sponsor contact addresses are stored in the contact table.How can I handle this Thanks Denny

      _ Offline
      _ Offline
      _Damian S_
      wrote on last edited by
      #2

      I assume you have primary key/foreign key relationships happening... if you do, use select @@IDENTITY to find the identify of the item you have inserted, so you can use it in the next insert. eg:

      insert into table1(name) values('Fred')
      go
      insert into table2(address, nameid) select '10 Smith Street', @@IDENTITY
      go

      I don't have ADHD, I have ADOS... Attention Deficit oooh SHINY!! Booger Mobile (n) - A bright green 1964 Ford Falcon - our entry into the Camp Quality esCarpade!! Do something wonderful - make a donation to Camp Quality today!!

      M 1 Reply Last reply
      0
      • M Member 4260270

        Hi, I have one stored procedure for inserting values to 5 tables at a time.So there are 5 insert statements in a single SP.Here some fields are common ie.there is customer address and sponsor address and all these addresses are stored in a single table.Firstly I insert customer details in the customer table and contact details to the contact table.Also sponsor contact addresses are stored in the contact table.How can I handle this Thanks Denny

        A Offline
        A Offline
        Andy_L_J
        wrote on last edited by
        #3

        ...or look at SCOPE_IDENTITY()

        I don't speak Idiot - please talk slowly and clearly 'This space for rent' Driven to the arms of Heineken by the wife

        1 Reply Last reply
        0
        • _ _Damian S_

          I assume you have primary key/foreign key relationships happening... if you do, use select @@IDENTITY to find the identify of the item you have inserted, so you can use it in the next insert. eg:

          insert into table1(name) values('Fred')
          go
          insert into table2(address, nameid) select '10 Smith Street', @@IDENTITY
          go

          I don't have ADHD, I have ADOS... Attention Deficit oooh SHINY!! Booger Mobile (n) - A bright green 1964 Ford Falcon - our entry into the Camp Quality esCarpade!! Do something wonderful - make a donation to Camp Quality today!!

          M Offline
          M Offline
          Member 4260270
          wrote on last edited by
          #4

          Thanks

          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