Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
I need to write a stored procedure.One table contains Serial_Number and WorkOrders, and four (4) other tables contain the records for the parts by Serial_Number.I need to create a query that allows me to search for parts based on a WorkOrder.I need to pull all Serial_Numbers for a given WorkOrder, then search the other tables for all instances of those Serial_Numbers, Testers, TestDates, and Status.What is the best way to create a Stored Procedure like this?EXEC sp_AllByWorkOrder '{0}'(Using SQL Server 2000 Enterprise and Visual Studio)Avoid Sears Home Improvement
jp2code
Posting Yak Master
175 Posts
Posted - 2008-08-20 : 17:09:12
Here is an example of what I am after, but I am not great at SQL Queries, so this only to get the point across:
CREATE PROCEDURE sp_AllByWorkOrder(@WO nvarchar(10)) ASSELECT Serial_Number, Tester, TestDate, StatusFROM dbo.Machines, dbo.Assembly, dbo.ShippingWHERE Serial_Number IN ( SELECT Serial_Number FROM dbo.Orders WHERE WorkOrder=@WO )
Thanks visakh16.I wound up learning how to create a table on the fly:> SELECT Serial_Number> INTO #t> FROM dbo.MainTable> WHERE ([WorkOrder_Number]=@WO)> ORDER BY Serial_Number> Avoid Sears Home Improvement
visakh16
Very Important crosS Applying yaK Herder
52326 Posts
Posted - 2008-08-21 : 09:34:50
quote:Originally posted by jp2code Thanks visakh16.I wound up learning how to create a table on the fly:> SELECT Serial_Number> INTO #t> FROM dbo.MainTable> WHERE ([WorkOrder_Number]=@WO)> ORDER BY Serial_Number> Avoid Sears Home Improvement
You dont need a temp table. you can directly join main table onto others using SerialNo and retrive matching fields as shown earlier.