SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Select from multiple table
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Patyk
Starting Member

24 Posts

Posted - 03/07/2014 :  14:59:51  Show Profile  Reply with Quote
I like to know if i can modify my procedure to acually insert data from more than one table. The second table DS_Control table is not linked with the other table. It only contains one line.
BEGIN


INSERT INTO Reporting.dbo.DailyWarehouseValues
(FiscalYear,FiscalMonth,EntryDate, StockCode ,Warehouse,QtyOnHand,QtyAllocated,QtyOnOrder,QtyOnBackOrder,QtyInTransit,QtyAllocatedWip)
Select FYear, FMonth
FROM Reporting.dbo.DS_ControlTable;

Select GETDATE(), StockCode ,Warehouse,QtyOnHand,QtyAllocated,QtyOnOrder,QtyOnBackOrder,QtyInTransit,QtyAllocatedWip
FROM companyB.dbo.InvWarehouse;

WHERE Warehouse in ('01', '02', '03')
END

tkizer
Almighty SQL Goddess

USA
36672 Posts

Posted - 03/07/2014 :  15:09:08  Show Profile  Visit tkizer's Homepage  Reply with Quote
You might need to add TOP 1, see if this works:

INSERT INTO Reporting.dbo.DailyWarehouseValues
(FiscalYear,FiscalMonth,EntryDate, StockCode ,Warehouse,QtyOnHand,QtyAllocated,QtyOnOrder,QtyOnBackOrder,QtyInTransit,QtyAllocatedWip)
Select (Select FYear FROM Reporting.dbo.DS_ControlTable), (Select FMonth
FROM Reporting.dbo.DS_ControlTable), GETDATE(), StockCode ,Warehouse,QtyOnHand,QtyAllocated,QtyOnOrder,QtyOnBackOrder,QtyInTransit,QtyAllocatedWip
FROM companyB.dbo.InvWarehouse;
WHERE Warehouse in ('01', '02', '03')


Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000