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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | 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
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Patyk
Yak Posting Veteran

74 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
38200 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  
 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.02 seconds. Powered By: Snitz Forums 2000