?
Solved

Convert Access crosstab query to SQL Server equivalent

Posted on 2004-11-16
4
Medium Priority
?
1,062 Views
Last Modified: 2008-02-07
Just need a conversion of an Access crosstab query to a SQL Server equivalent.

The query is as follows:

TRANSFORM Count(tblTrans.keyFUser) AS CountOfkeyFUser SELECT Val(Month([Timestamp])) AS [Month] FROM tblTrans WHERE (((Year([Timestamp]))=2004)) GROUP BY Val(Month([Timestamp])) ORDER BY Val(Month([Timestamp])) PIVOT "Users";

tblTrans contains a record for each "transaction" on the site. So the query basically has a row for each month (with each month indicated by its numeric value) and the value of CountOfkeyFUser will be the number of "transactions" in that month.

The structure of tblTrans is as follows:

keyTrans - Int (identity, auto-increment)
keyFUser - Int
Type - SmallInt
ID - Int
Timestamp - smalldatetime

Typical record:

keyTrans = 63 (unique identifier of the transaction)
keyFUser = 24 (user that performed the transaction)
Type = 1 (type of transaction)
ID = 44 (product the transaction relates to)
Timestamp = 30/09/2004 12:37:05 (date/time transaction occurred)

Thanks in advance
0
Comment
Question by:jonnyboy69
  • 2
4 Comments
 
LVL 1

Accepted Solution

by:
mjm42 earned 2000 total points
ID: 12598838
Maybe I don't understand your problem but why don't the following work:

SELECT MONTH(Timestamp), COUNT(keyFUser) AS Users FROM tblTrans
WHERE YEAR(Timestamp) = 2004
GROUP BY MONTH(Timestamp)
ORDER BY MONTH(Timestamp)
0
 
LVL 16

Expert Comment

by:muzzy2003
ID: 12598927
That's my understanding of the question as well, I don't think you're going mad!
0
 

Author Comment

by:jonnyboy69
ID: 12599368
Awww crap I am going mad ... it's been a long day alright! ;)

The last in a long list of errors from someone elses code and it looked hard! So I thought i'd get someone else to do it. Please have 500 points.

/switches brain on
0
 
LVL 16

Expert Comment

by:muzzy2003
ID: 12599400
Why do I never see these questions quickly enough? ;)
0

Featured Post

Free recovery tool for Microsoft Active Directory

Veeam Explorer for Microsoft Active Directory provides fast and reliable object-level recovery for Active Directory from a single-pass, agentless backup or storage snapshot — without the need to restore an entire virtual machine or use third-party tools.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
Suggested Courses

579 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question