how to retrieve parent-child table from stored procedure

I have to table in my database sql server2005 "order" and "order details" I design a stored procedure to retrieve booth tables I want to fill my dataset with booth tables in vb.net 2008

the stored procedure code :
^
^
^
ALTER PROCEDURE [dbo].[PO_PurchaseOrder_Retrieve]
(
  @PurchaseOrderId int,
  
)
AS
  /** RETRIEVE THE MAIN ENTRY FROM THE TABLE **/
  SELECT PurchaseOrderId, Timestamp, Version, LastModUserId, LastModDttm, OrderStatus, OrderNumber, VendorOrderNumber, OrderDate, VendorId, PaymentTermsId, Carrier, ContactName, Phone, VendorAddress1, VendorAddress2, VendorCity, VendorState, VendorCountry, VendorPostalCode, VendorAddressRemarks, VendorAddressType, ShipToAddress1, ShipToAddress2, ShipToCity, ShipToState, ShipToCountry, ShipToPostalCode, ShipToAddressRemarks, ShipToAddressType, RequestShipDate, OrderTaxCodeId, OrderRemarks, OrderSubTotal, OrderTax1, OrderTax2, OrderExtra, OrderTotal, Tax1Rate, Tax2Rate, CalculateTax2OnTax1, Tax1Name, Tax2Name, ReceiveRemarks, PaymentMethod, CalculatedDueDate, DueDate, DatePaid, AmountPaid, PaymentBalance, PaymentRemarks, ReturnRemarks, ReturnDate, ReturnSubTotal, ReturnTax1, ReturnTax2, ReturnExtra, ReturnTotal, ReturnFee, ReturnRefunded, ReturnCredit, UnstockRemarks, Custom1, Custom2, Custom3, Custom4, Custom5, TaxOnShipping
  FROM [PO_PurchaseOrder]
  WHERE PurchaseOrderId = @PurchaseOrderId
 
/** Get Child Objects **/
  SELECT PurchaseOrderLineId, Timestamp, Version, PurchaseOrderId, ItemId, ItemType, Description, VendorItemCode, Quantity, UnitPrice, ItemTaxCodeId, SubTotal
  FROM PO_PurchaseOrder_Line WHERE  PurchaseOrderId = @PurchaseOrderId

Open in new window

onecd2000Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

QPRCommented:
Inner join (see code below).
Just work out which fields in your select come from P1 or P2 and add this to them e.g.
e.g. select P1.purchaseorderid
As you are returning a single recordset I'm guessing you can drop off a lot of the items in the SELECT as they may (should) be the same from each table


SELECT PurchaseOrderId, Timestamp, Version, LastModUserId, LastModDttm, OrderStatus, OrderNumber, VendorOrderNumber, OrderDate, VendorId, PaymentTermsId, Carrier, ContactName, Phone, VendorAddress1, VendorAddress2, VendorCity, VendorState, VendorCountry, VendorPostalCode, VendorAddressRemarks, VendorAddressType, ShipToAddress1, ShipToAddress2, ShipToCity, ShipToState, ShipToCountry, ShipToPostalCode, ShipToAddressRemarks, ShipToAddressType, RequestShipDate, OrderTaxCodeId, OrderRemarks, OrderSubTotal, OrderTax1, OrderTax2, OrderExtra, OrderTotal, Tax1Rate, Tax2Rate, CalculateTax2OnTax1, Tax1Name, Tax2Name, ReceiveRemarks, PaymentMethod, CalculatedDueDate, DueDate, DatePaid, AmountPaid, PaymentBalance, PaymentRemarks, ReturnRemarks, ReturnDate, ReturnSubTotal, ReturnTax1, ReturnTax2, ReturnExtra, ReturnTotal, ReturnFee, ReturnRefunded, ReturnCredit, UnstockRemarks, Custom1, Custom2, Custom3, Custom4, Custom5, TaxOnShipping
  FROM [PO_PurchaseOrder] P1
  inner join PO_PurchaseOrder_Line P2
  	on p1.purchaseorderid = p2.purchaseorderid
  WHERE  P1.PurchaseOrderId = @PurchaseOrderId
 

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
onecd2000Author Commented:
Thanks it was helpful
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Databases

From novice to tech pro — start learning today.