12,068,508 members (70,553 online)
Rate this:
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 13-Feb-13 20:35pm
isi19520
Edited 13-Feb-13 21:29pm
v2
Aarti Meswania 14-Feb-13 1:49am

not clear question
what is your table and fields ?

Rate this:

## 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`
Rate this:

## 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```
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
Rate this:

## Solution 3

select sum(amt),id from tablex where date='2012-10-10' and id= 1 group by id
v2
Rate this:

## 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
```

Top Experts
Last 24hrsThis month
 CHill60 439 OriginalGriff 214 Richard Deeming 184 CPallini 162 Dave Kreskowiak 145
 Dave Kreskowiak 2,126 OriginalGriff 1,501 Richard MacCutchan 1,455 CPallini 1,042 Sergey Alexandrovich Kryukov 992