Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Select from multiple table

Author  Topic 

Patyk
Yak Posting Veteran

74 Posts

Posted - 2014-03-07 : 14:59:51
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

38200 Posts

Posted - 2014-03-07 : 15:09:08
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
   

- Advertisement -