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. uniting 3 tables

uniting 3 tables

Scheduled Pinned Locked Moved Database
sharepointhelpquestionannouncement
2 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.
  • S Offline
    S Offline
    suni_dotnet
    wrote on last edited by
    #1

    Hi All, iam using if else for updating and inserting, i need to do this for 3 tables how can i unite them using unions or join.. IF EXISTS (SELECT col1,col2,col3,col4 FROM TableB) UPDATE TableB SET col2=TableA.col2, col3=TableA.col3, col4=TableA.col4 from TableA where (TableB.col1 = TableA.col1 and TableA.Col5='no') ELSE INSERT INTO TableB (col1,col2,col3,col4) select TableA.col1,TableA.col2,TableA.col3,TableA.col4 from TableA where TableA.Col5='no'; and i need to repeat this code for TableC and TableD (along with TableA) for updating TableB. How can i unite all in one procedure.Hope iam clear if not i can...Please help... may be the solution is simple but i dont know... i tried but unable to ... i cannot use 3 sp's, i need all in one procedure Thanks in advance

    C 1 Reply Last reply
    0
    • S suni_dotnet

      Hi All, iam using if else for updating and inserting, i need to do this for 3 tables how can i unite them using unions or join.. IF EXISTS (SELECT col1,col2,col3,col4 FROM TableB) UPDATE TableB SET col2=TableA.col2, col3=TableA.col3, col4=TableA.col4 from TableA where (TableB.col1 = TableA.col1 and TableA.Col5='no') ELSE INSERT INTO TableB (col1,col2,col3,col4) select TableA.col1,TableA.col2,TableA.col3,TableA.col4 from TableA where TableA.Col5='no'; and i need to repeat this code for TableC and TableD (along with TableA) for updating TableB. How can i unite all in one procedure.Hope iam clear if not i can...Please help... may be the solution is simple but i dont know... i tried but unable to ... i cannot use 3 sp's, i need all in one procedure Thanks in advance

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      I don't fully see what you are trying to do. But if "unite all in one procedure" you mean that it all happens as one operation then you might want to look at transactions. If you wrap all of this up in a transaction it will appear as one procedure. Nothing else accessing the database will be able to see a half updated set of data. They'll either see the data as it was before the transaction, or they'll be locked out until the transaction is complete and when the lock is released they'll see it as the complete result.

      *Developer Day Scotland - Free community conference *Colin Angus Mackay's Blog *Latest Scottish Developers Newsletter


      Vogon Building and Loan advise that your planet is at risk if you do not keep up repayments on any mortgage secured upon it. Remember that the force of gravity can go up as well as down.

      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