Click here to Skip to main content
15,887,683 members
Home / Discussions / Database
   

Database

 
GeneralRe: How to loop or something a temp distinct table to sum up the totals Pin
Jörgen Andersson4-Jan-14 21:04
professionalJörgen Andersson4-Jan-14 21:04 
GeneralRe: How to loop or something a temp distinct table to sum up the totals Pin
jkirkerx5-Jan-14 7:57
professionaljkirkerx5-Jan-14 7:57 
GeneralRe: How to loop or something a temp distinct table to sum up the totals Pin
jkirkerx5-Jan-14 8:29
professionaljkirkerx5-Jan-14 8:29 
GeneralRe: How to loop or something a temp distinct table to sum up the totals Pin
Christian Graus5-Jan-14 16:02
protectorChristian Graus5-Jan-14 16:02 
GeneralRe: How to loop or something a temp distinct table to sum up the totals Pin
Jörgen Andersson5-Jan-14 22:19
professionalJörgen Andersson5-Jan-14 22:19 
GeneralRe: How to loop or something a temp distinct table to sum up the totals Pin
jkirkerx6-Jan-14 6:06
professionaljkirkerx6-Jan-14 6:06 
GeneralRe: How to loop or something a temp distinct table to sum up the totals Pin
Jörgen Andersson5-Jan-14 22:16
professionalJörgen Andersson5-Jan-14 22:16 
GeneralRe: How to loop or something a temp distinct table to sum up the totals Pin
jkirkerx6-Jan-14 6:15
professionaljkirkerx6-Jan-14 6:15 
I think I ended up doing that, and was amazed at how it worked.

Let me check,

This is the SQL in the asp.net function I used for testing. I kept the DateTimeFromParts because I stored the order date as a timestamp, and not a date, and had to be more precise with the hours minutes and seconds. I was originally BETWEEN, but I could not get a result, and it took me hours to figure it out, plus I had upgraded to SQL Server 2012 at the time. Then the timestamp dawned on me, and I spent another hour figuring out how to be more precise. I'd rather use between, and not use anything specific to 2012.

I SUM the Qty to get 7, and it worked on the test data set, not sure if I was just lucky to get that value, I need to find more data on different days to fully check it.

"DECLARE @startDate AS DATE; " & _
        "DECLARE @stopDate AS DATE; " & _
        "SET @startDate = DATETIMEFROMPARTS(@Year, @Month, @Day, 0, 0, 0, 0); " & _
        "SET @stopDate = DATETIMEFROMPARTS(@Year, @Month, @Day, 23, 59, 59, 999); " & _
        "DECLARE @SummaryItems TABLE(" & _
            "PartNumber VarChar(80), " & _
            "ThumbNail VarChar(250), " & _
            "SDescription VarChar(250), " & _
            "Qty INT, " & _
            "Cost Decimal, " & _
            "Price Decimal, " & _
            "SubTotal Decimal " & _
        ") " & _
        "INSERT INTO @SummaryItems (PartNumber, ThumbNail, SDescription, Qty, Cost, Price, SubTotal) " & _
        "SELECT PartNumber, ThumbNail, SDescription, SUM(Qty), Cost, Price, SUM(Qty * Price) From CompletedOrdersCart  " & _
        "WHERE OrderDate > @startDate AND OrderDate < @stopDate " & _
        "GROUP BY PartNumber, Thumbnail, SDescription, Qty, Cost, Price " & _
        "SELECT PartNumber, Thumbnail, SDescription, Qty, Cost, Price, SubTotal FROM @SummaryItems;"


modified 6-Jan-14 12:44pm.

GeneralRe: How to loop or something a temp distinct table to sum up the totals Pin
Jörgen Andersson6-Jan-14 8:17
professionalJörgen Andersson6-Jan-14 8:17 
GeneralRe: How to loop or something a temp distinct table to sum up the totals Pin
jkirkerx6-Jan-14 7:01
professionaljkirkerx6-Jan-14 7:01 
GeneralRe: How to loop or something a temp distinct table to sum up the totals Pin
Jörgen Andersson6-Jan-14 8:36
professionalJörgen Andersson6-Jan-14 8:36 
GeneralRe: How to loop or something a temp distinct table to sum up the totals Pin
jkirkerx6-Jan-14 9:02
professionaljkirkerx6-Jan-14 9:02 
QuestionNot work correctly Pin
Member 100045982-Jan-14 23:05
Member 100045982-Jan-14 23:05 
AnswerRe: Not work correctly Pin
Shameel2-Jan-14 23:14
professionalShameel2-Jan-14 23:14 
GeneralRe: Not work correctly Pin
Member 100045983-Jan-14 0:07
Member 100045983-Jan-14 0:07 
GeneralRe: Not work correctly Pin
Shameel3-Jan-14 0:41
professionalShameel3-Jan-14 0:41 
GeneralRe: Not work correctly Pin
Richard MacCutchan3-Jan-14 1:11
mveRichard MacCutchan3-Jan-14 1:11 
GeneralRe: Not work correctly Pin
Simon_Whale3-Jan-14 1:53
Simon_Whale3-Jan-14 1:53 
GeneralRe: Not work correctly Pin
Member 100045983-Jan-14 3:57
Member 100045983-Jan-14 3:57 
SuggestionRe: Not work correctly Pin
Shameel6-Jan-14 3:40
professionalShameel6-Jan-14 3:40 
Questioninsert information of filed to another fielads Pin
f,amiri88227-Dec-13 9:11
f,amiri88227-Dec-13 9:11 
AnswerRe: insert information of filed to another fielads Pin
Andrius Leonavicius27-Dec-13 12:23
professionalAndrius Leonavicius27-Dec-13 12:23 
AnswerRe: insert information of filed to another fielads Pin
Shameel2-Jan-14 4:09
professionalShameel2-Jan-14 4:09 
QuestionMySql Connection String 'localhost' not working Pin
Dominick Marciano23-Dec-13 21:17
professionalDominick Marciano23-Dec-13 21:17 
QuestionRe: MySql Connection String 'localhost' not working Pin
Eddy Vluggen24-Dec-13 6:59
professionalEddy Vluggen24-Dec-13 6:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.