Question : T-SQL Count Issue

Hi All, long time browser, first time asking.

I am required to do a count() of employees and there transactions between dates.

Table looks a bit like this (made up for business privacy of course.)

Table Name UserDefault
UserName as Primary Key

TransactionAudit
UserName as secondary key
UpdateDateTime as small datetime
Transaction ID as primary key
OutcomeType  values 1-6

Could someone please help me with a better method of counting?

I am using the following code for my query

Thanks

Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
(
        select  count (ta.transactiontime) 
	from 	transactionaudit ta 
	where 	ta.outcometype = 1 
	and ta.username = ud.username
	and ta.updatedatetime= '1 jan 2008'
)
        as transaction_count

Answer : T-SQL Count Issue

I am not sure about what you were trying to do exactly, but try the query below, notice the line you can either remove or provide the specific user to get the count for.
1:
2:
3:
4:
5:
select ta.username, count(ta.transactiontime) as transaction_count
from 	transactionaudit ta 
where 	ta.outcometype = 1 
and ta.username = 'any user name'  -- Leave this line off for a list of all users and their counts
Group by ta.username
Random Solutions  
 
programming4us programming4us