-
Jan 22nd, 2014, 04:57 AM
#1
Thread Starter
Member
[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!
-
Jan 22nd, 2014, 05:13 AM
#2
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?
-
Jan 22nd, 2014, 05:24 AM
#3
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
-
Jan 22nd, 2014, 06:24 AM
#4
Thread Starter
Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|