Click here to Skip to main content
15,896,727 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HI

I am currently creating a report for my client and would like to know how would i be able to calculate the amount of records processed by a user for each day.


My table is Stage1


id(int),product(Nvarchar),date(datetime),userid(int),stage(int)

what would my query be to select the amount of products entered by a user?

i need to get the count of products passed per day by a user

Select Sum(userid),Workcompleted from Table group by workcompleted
Posted
Updated 13-Feb-13 20:29pm
v2
Comments
Aarti Meswania 14-Feb-13 1:49am    
not clear question
what is your table and fields ?

SQL
Select Sum(Workcompleted ) from Table where userid = @userid 


would do it, assuming workcompleted is the number of records processed

if you just want to counmt the records then

SQL
select count(*) from Table where userId = @userId
 
Share this answer
 
try below T-SQL code :

SQL
CREATE TABLE #TEMP
(
	ITEM	VARCHAR(50),
	AMOUNT	INT,
	INDATE  DATETIME,
	USERID	INT
)

INSERT INTO #TEMP VALUES('WATCH',500,'02/13/2013',1)
INSERT INTO #TEMP VALUES('BELT',300,'02/13/2013',1)
INSERT INTO #TEMP VALUES('WALLET',600,'02/13/2013',2)
INSERT INTO #TEMP VALUES('TROUSERS',1600,'02/13/2013',2)

SELECT USERID,INDATE,SUM(AMOUNT) AS TOTALAMOUNT
FROM #TEMP
GROUP BY USERID,INDATE

DROP TABLE #TEMP
 
Share this answer
 
Comments
isi19 14-Feb-13 2:06am    
My table is


id,product,date,userid,stage

what would my query be to select the amount of products entered by a user?
isi19 14-Feb-13 2:06am    
i need to get the count of products passed per day per user
Bhushan Shah1988 14-Feb-13 7:44am    
try this :

CREATE TABLE #TEMP
(
ITEM VARCHAR(50),
AMOUNT INT,
INDATE DATETIME,
USERID INT
)

INSERT INTO #TEMP VALUES('WATCH',500,'02/13/2013',1)
INSERT INTO #TEMP VALUES('WATCH',500,'02/13/2013',1)
INSERT INTO #TEMP VALUES('BELT',300,'02/13/2013',1)
INSERT INTO #TEMP VALUES('WALLET',600,'02/13/2013',2)
INSERT INTO #TEMP VALUES('WALLET',700,'02/13/2013',2)
INSERT INTO #TEMP VALUES('TROUSERS',1600,'02/13/2013',2)
INSERT INTO #TEMP VALUES('TROUSERS',1300,'02/13/2013',2)

SELECT USERID,COUNT(*) AS NoofProducts
FROM #TEMP
GROUP BY USERID

DROP TABLE #TEMP
select sum(amt),id from tablex where date='2012-10-10' and id= 1 group by id
 
Share this answer
 
v2
The best way to achieve that is to use Stored procedure[^], like this:
SQL
CREATE PROCEDURE GetAmountPerUserAndDate
    @dateFrom AS DATE,
    @dateTo AS DATE

AS 

BEGIN

    SELECT [userid], [date], SUM(Amount)
    FROM Stage1
    WHERE [date] BETWEEN COALESCE(@dateFrom,GETDATE()) AND COALESCE(@DateTo,GETDATE())
    GROUP BY [userid], [date]
    ORDER By [userid], [date]

END
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900