please help to write a stored procedure for BULK INSERTION

sp_beginner's Avatar, Join Date: Oct 2011
Newbie Member
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.
0
sql-programs's Avatar, Join Date: Oct 2009
Go4Expert Member
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