I have this function in sql server 2005:
And I get the different values on their respected cells....What I would like to know or get some ideas on, is how to make the same GuestID, that comes up more than once on the table, be on the same cells together one below the other instead of two separate cells...For example: Let's say there are more than one GuestID's that are the same, so it has same GuestFirstName, LastName and personal info the same, but the Sales part of it changes because it is a different Sale. Once again, I need some ideas on how to make that specific Guest(Same GuestID) have the different sales included for the same person...any enlightenment will be greatly appreciated. Let me know if this isn't clear.
Code:
ALTER FUNCTION dbo.fnGuestID()
RETURNS TABLE
AS
RETURN SELECT g.GuestID,g.GuestFirstName,g.GuestLastName,g.GuestAddress,g.Country,g.GuestPhone,g.GuestEmail,s.SaleTotal,s.InvoiceNumber,s.SaleItem,s.PaymentType,s.SaleDiscount,s.Date,s.Quantity,s.SalePrice
From Guest AS g, Sales As s
WHERE g.GuestID = s.GuestID AND s.SalesStatus = 'ToGuestInvoice'
GROUP BY g.GuestID,g.GuestFirstName,g.GuestLastName,g.GuestAddress,g.Country,g.GuestPhone,g.GuestEmail,s.SaleTotal,s.InvoiceNumber,s.SaleItem,s.PaymentType,s.SaleDiscount,s.Date,s.Quantity,s.SalePrice
Comment