|
|
|||||||||
|
|||||||||
|
|||||||||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
|
|
#1
|
||||
|
||||
|
Database - Recordset - Display correct SUM
I have this SQL statement in my ASP page that retrieves some records from a database. There are 3 records in the database but I want it to show me the sum of column LQShipped and show me the latest date in the LastShipDate column. Currently it shows me all three records and the LQShipped is not totalled. I just want one record with the total of LQShipped and the latest date in the LastShipDate.
Code:
SELECT ID, SoldTo, SoldToName, SoldToAdd1, SoldToAdd2, SoldToAdd3, SoldToAdd4, SoldToCty, SoldToState, SoldToZip, LastShipDate, ItemNumber, ItemDescription, UOM, Conversion, SUM(LQShipped) as LQShipped, TQOrder, LSTake, Balance, InStore, SellThru, RunningSellThru, RepID, RepName, Stamp FROM dbo.Inventory WHERE SoldTo = '" & Request.Form("SoldTo") & "' AND ItemNumber = '" & Request.Form("Item") & "' GROUP BY ID, SoldTo, SoldToName, SoldToAdd1, SoldToAdd2, SoldToAdd3, SoldToAdd4, SoldToCty, SoldToState, SoldToZip, LastShipDate, ItemNumber, ItemDescription, UOM, Conversion, LQShipped, TQOrder, LSTake, Balance, InStore, SellThru, RunningSellThru, RepID, RepName, Stamp ORDER BY ItemDescription, LastShipDate ASC
Thanks in advance for your help.
__________________
If I have been of useful help please don't hesitate to provide me with some Reputation points Be in Control of your Data and get it your way. Customized Web Applications. |
|
#2
|
||||
|
||||
|
try this:
Code:
SELECT
ID, SoldTo, SoldToName, SoldToAdd1, SoldToAdd2, SoldToAdd3, SoldToAdd4,
SoldToCty, SoldToState, SoldToZip, Max(LastShipDate) as LastShipDate, ItemNumber, ItemDescription,
UOM, Conversion, SUM(LQShipped) as LQShipped, TQOrder, LSTake, Balance,
InStore, SellThru, RunningSellThru, RepID, RepName, Stamp
FROM dbo.Inventory
WHERE SoldTo = '" & Request.Form("SoldTo") & "'
AND ItemNumber = '" & Request.Form("Item") & "'
GROUP BY
ID, SoldTo, SoldToName, SoldToAdd1, SoldToAdd2, SoldToAdd3, SoldToAdd4,
SoldToCty, SoldToState, SoldToZip, ItemNumber, ItemDescription,
UOM, Conversion, TQOrder, LSTake, Balance,
InStore, SellThru, RunningSellThru, RepID, RepName, Stamp
ORDER BY ItemDescription ASC
__________________
Come JOIN the party!!! Quote of the Month: Trouble: Luck can't last a lifetime unless you die young. Questions to Ponder: Do cemetery workers prefer the graveyard shift? iif([sarcasm]=true,iif([you have to ask]=true,"didn't work","ha ha ha"),"not sarcasm") copyright© 2008 sbenj69 Last edited by mehere : April 8th, 2008 at 07:59 AM. |
|
#3
|
||||
|
||||
|
still showing me 3 records and no total in the LQShipped column. Any other suggestions?
|
|
#4
|
||||
|
||||
|
it shouldn't. i ran a quick test of the query and it seemed to work here, provided every column in your GROUP BY clause is exactly the same.
|
|
#5
|
||||
|
||||
|
the only columns that are not the same are the LastShipDate hence i just want to show the latest date and the LQShipped hence i want to sum it up. Any ideas?
|
|
#6
|
||||
|
||||
|
if that's the case, then what i posted should work. can you post the DDL for your table along with insert statements for those 3 recrods and i can test this. if i could replicate your table along with the 3 records you're talking about, i could get a better picture of what your issue is. but as stated, a quick test shows that this sample will work.
|
|
#7
|
||||
|
||||
|
-->Moved to SQL Development as it's query related not ASP related.
|
|
#8
|
||||
|
||||
|
this is a quick sample that i did
Code:
create table testtable ( id int, soldto int, soldtoname varchar(25), lastshipdate smalldatetime, lqshipped money ) insert into testtable values (1,1,'jane doe','01/05/2008',5.00) insert into testtable values (1,1,'jane doe','02/05/2008',10.00) insert into testtable values (1,1,'jane doe','03/05/2008',15.00) select id, soldto, soldtoname, max(lastshipdate), sum(lqshipped) from testtable group by id, soldto, soldtoname the only thing i can think of in your case ... is the ID a unique value for each record. if so, you can't use it in your group by clause. |
|
#9
|
|||
|
|||
|
moracom
Take a look at: forums.aspfree.com/asp-development-5/asp-data-read-and-update-problems-220470.html The code I put in there does a sumTotal that adds the total of each record and displays the result at the bottom. After the database is opened it defines the variable and sets it to zero Dim sumTotal sumTotal = "0.00" It then goes into the Do/While loop After all of the variables are defined the sumTotal is calculated using the current sum plus the current total value It then returns to the loop until end of file. The sumTotal is then displayed |
![]() |
| Viewing: ASP Free Forums > Database > SQL Development > Database - Recordset - Display correct SUM |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|
|
|
|