CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Jan 2008
    Location
    Belize
    Posts
    53

    Lightbulb Need SQL Function Brainwave

    I have this function in sql server 2005:
    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
    And I get the table below after i excute....What I would like to know or get some ideas on, is how to make the same GuestID, that comes up twice at the end, be on the same cells together one below the other instead of two separate cells...Let me know if this isn't clear.
    Attached Images Attached Images  

  2. #2
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: Need SQL Function Brainwave

    I guess they are already in order.

    Group By clause will also get them in order like Order By does.

    Rr may be I misunderstood your question.

  3. #3
    Join Date
    Nov 2007
    Posts
    110

    Re: Need SQL Function Brainwave

    I am not sure I am completely understanding you, but if I am...you can't get them "on the same cells" because you are also pulling their sale information, which is unique. If you were just pulling the guest information, you would be able to by using the distinct keyword.

  4. #4
    Join Date
    Jan 2008
    Location
    Belize
    Posts
    53

    Re: Need SQL Function Brainwave

    Well something like that I would want because basically the Guest information should remain the same, can u show me an example if it were just the Sales table?

  5. #5
    Join Date
    Jan 2008
    Location
    Belize
    Posts
    53

    Need SQL Function Brainwave

    To Make it clearer, I would like GuestID '129", since it's the same Guest twice, I would like to retrieve the sales part of it together, so that when i print it...it shows the Guest with both sales on it...but so far I can't figure out another way or a way to do it.

  6. #6
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Need SQL Function Brainwave

    Guest 129 in a cell two cells high? Like MSHFlexgrid? Not sure what it's called in C#. MS Hierarchical Flex Grid
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  7. #7
    Join Date
    Jan 2008
    Location
    Belize
    Posts
    53

    Re: Need SQL Function Brainwave

    Hey well, I don't believe that it's possible for two separate rows to partially join because with the things I need to retrieve it will cause the rows to break...I think it's gonna be very tedious when it comes to me printing each value in its respective cell since the number of sales can become large and will therefore cause too much hazardous work, so what I'm gonna do is this:
    Code:
    "SELECT g.GuestID,g.GuestFirstName,g.GuestLastName,g.GuestAddress,g.Country,g.GuestPhone,g.GuestEmail,
                sum(s.SaleTotal) as TotalSaleOfThisGuestID, count(*) as NumberOfSaleOfThisGuestID
                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"
    In which I still would like to obtain the date for each sale separate...and it comes to mind to create other columns where the other dates could be entered...I will try that and hopefully it works. Thanks for all ur suggestions, appreciate it

    --GM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured