Question

I am trying to get a count of trans per employee by day. The table i am pulling from has the long date form with hours/min/secs and think that is the reason i am unable to count the transactions b/c they are being treated as individual records b/c of the long date time.

So in the Select query, i tried to convert the date, but get an error message: Cannot call methods on date.

here is my code

SELECT ITR_EmployeeID, 
CONVERT(DATE, ITR_TransDate, 1) AS TransDate, 
COUNT(ITR_TransType) AS TC
FROM  dbo.ITR
WHERE (ITR_EmployeeID IN (N'sweda', N'bakja', N'gebwa')) 
AND (ITR_TransType LIKE N'PO Inspect') 
AND (ITR_TransDate BETWEEN @FromDate AND @ToDate)
GROUP BY ITR_EmployeeID, ITR_TransDate

What i am looking for is the Transtype to be counted by date and grouped by employeeID

thanks!!

Was it helpful?

Solution

You should do this in a query window, not in some view or query designer. Stop using those. Please.

SELECT 
  ITR_EmployeeID, 
  CONVERT(DATE, ITR_TransDate) AS TransDate, 
  COUNT(ITR_TransType) AS TC 
FROM dbo.ITR 
WHERE (ITR_EmployeeID IN (N'sweda', N'bakja', N'gebwa')) 
AND (ITR_TransType LIKE N'PO Inspect') 
AND (ITR_TransDate >= @FromDate AND ITR_TransDate < DATEADD(DAY, 1, @ToDate))
GROUP BY ITR_EmployeeID, CONVERT(DATE, ITR_TransDate);

Get this query working with the right results in SQL Server Management Studio (again, in a query window, not the buggy visual designers). THEN get it working in whatever application code you're trying to implement it in, and deal with those issues separately (or create a stored procedure and avoid any problems you're having incorporating T-SQL query text into some other app).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top