12,397,575 members (60,118 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 19:35pm
isi19520
Updated 13-Feb-13 20: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
 OriginalGriff 220 Richard MacCutchan 215 Richard Deeming 214 Karthik Bangalore 190 F-ES Sitecore 100
 OriginalGriff 6,283 Karthik Bangalore 2,572 ppolymorphe 2,455 F-ES Sitecore 1,897 Richard MacCutchan 1,842