Go4Expert

Go4Expert (http://www.go4expert.com/)
-   SQL Server (http://www.go4expert.com/forums/sql-server-forum/)
-   -   please help to write a stored procedure for BULK INSERTION (http://www.go4expert.com/forums/help-write-stored-procedure-bulk-t26954/)

sp_beginner 18Oct2011 12:52

please help to write a stored procedure for BULK INSERTION
 
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.

sql-programs 29Nov2011 11:38

Re: please help to write a stored procedure for BULK INSERTION
 
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


All times are GMT +5.5. The time now is 18:14.