please help to write a stored procedure for BULK INSERTION

Discussion in 'SQL Server' started by sp_beginner, Oct 18, 2011.

  1. sp_beginner

    sp_beginner New Member

    Joined:
    Oct 18, 2011
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    need help on writing a stored procedure.

    I have three tables from two different databases

    DB1.tb (

    Ps_ID(pk,int,not null),

    Po_ID(int,not null))


    --being Ps_ID distributed as per values into



    DB2.tb1 (

    Ps_ID(int,not null),

    DT (datetime,not null),

    val (float,not null))



    DB2tb2 (

    ps_ID(int,not null),

    DT (datetime,not null),

    val(float,not null))



    what would be the STORED PROCEDURE to BULK INSERT all the datas
    in a new table
    from DB2.tb1 and DB2.tb2 joinning DB1.tb ON Ps_ID

    this is my first post so please excuse me on the presentation part.
     
  2. sql-programs

    sql-programs New Member

    Joined:
    Oct 21, 2009
    Messages:
    14
    Likes Received:
    2
    Trophy Points:
    0
    Occupation:
    Software Developer
    Home Page:
    http://www.sql-programmers.com
    First create a new table and insert the records for following query

    CREATE TABLE tblnew
    (Ps_ID INTEGER NOT NULL,
    DT DATETIME NOT NULL,
    val FLOAT NOT NULL );
    GO

    INSERT dbo.tblnew (Ps_ID,DT,val)
    SELECT DB1.dbo.TB.Ps_ID, DB2.dbo.tb1.DT,DB2.dbo.tb1.val
    FROM DB2.dbo.tb1
    INNER JOIN DB1.dbo.tb ON DB1.dbo.TB.Ps_ID = DB2.dbo.tb1.Ps_ID
    UNION ALL
    SELECT DB1.dbo.TB.Ps_ID, DB2.dbo.tb2.DT,DB2.dbo.tb2.val
    FROM DB2.dbo.tb2
    INNER JOIN DB1.dbo.tb ON DB1.dbo.TB.Ps_ID = DB2.dbo.tb2.Ps_ID
    GO
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice