Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL
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 13-Feb-13 20:35pm
isi19462
Edited 13-Feb-13 21:29pm
v2
Comments
Aarti Meswania at 14-Feb-13 1:49am
   
not clear question
what is your table and fields ?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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
 
select count(*) from Table where userId = @userId
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

try below T-SQL code :
 
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
  Permalink  
Comments
isi19 at 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 at 14-Feb-13 2:06am
   
i need to get the count of products passed per day per user
Bhushan Shah1988 at 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
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

select sum(amt),id from tablex where date='2012-10-10' and id= 1 group by id
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

The best way to achieve that is to use Stored procedure[^], like this:
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
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 273
1 Maciej Los 255
2 Aajmot Sk 234
3 Richard MacCutchan 200
4 Marcin Kozub 195
0 OriginalGriff 7,903
1 Sergey Alexandrovich Kryukov 7,127
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,820


Advertise | Privacy | Mobile
Web01 | 2.8.1411023.1 | Last Updated 14 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100