Results 1 to 4 of 4

Thread: [RESOLVED] Multi Line SQL

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2013
    Posts
    62

    Resolved [RESOLVED] Multi Line SQL

    Hi,

    Could anyone help with, what I think needs a Multi Line SQL.

    I'm making a meal diary kind of program, in a section of the program adds up the calories, carbs, protein and fats for that day (and week) and displays the count.

    At the moment, the user is able to add a meal diary, and then it stores MemberID, the Date and Recipe Number. I need to be able to use all the recipe numbers for that particular user on that day(or week) to go get the values for the recipes calories, carbs etc so then I can add up all the values and create percentages etc.

    Could anyone give me some pointers on how to go about this because I've hit a dead end now haha!

    Thanks in advance!

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,350

    Re: Multi Line SQL

    Code:
    Dim command As New SqlCommand
    
    command.CommandText = "SELECT * FROM MyTable WHERE MemberID = @MemberID AND [Date] = @Date"
    command.Parameters.AddWithValue("@MemberID", memberID)
    command.Parameters.AddWithValue("@Date", Date.Today)
    That sort of thing?

  3. #3
    Super Moderator FunkyDexter's Avatar
    Join Date
    Apr 2005
    Location
    An obscure body in the SK system. The inhabitants call it Earth
    Posts
    7,902

    Re: Multi Line SQL

    JM's shown you how to talk to the database from your app but it sounds to me like you also need to know how to join two tables (meal and recipe) and use aggregate functions. I suspect your sql will actually look a bit more like this:-
    Code:
    Select sum(R.Calories), sum(R.Carbs), sum(R.Proteins), sum(R.Fats)
    From Recipes R
    Join Meals M
      on R.RecipeID = M.RecipeID
    Where M.MemberID = @MemberID
    And M.[Date] = @Date
    The best argument against democracy is a five minute conversation with the average voter - Winston Churchill

    Hadoop actually sounds more like the way they greet each other in Yorkshire - Inferrd

  4. #4

    Thread Starter
    Member
    Join Date
    Jan 2013
    Posts
    62

    Re: Multi Line SQL

    Ah thanks a lot. Think I've got it sorted now. Massive help, cheers!

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