Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 Database Design and Application Architecture
 How to change data display in sql query

Author  Topic 

Syima
Starting Member

13 Posts

Posted - 2007-10-02 : 02:56:07
Hi there

Assuming this is the query used to return this result:

select dept.name, count(prj.id) from department dept, project prj where prj.id = dept.uid group by dept.name

Dept, TotalProj
A , 10
B , 5
C , 2

Question: How do I change the query so that the result will return as follows:

Dept/TotalProj
A, B, C
10, 5, 2

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-10-02 : 03:05:06
Are you using SQL Server 2005? Try out PIVOT keyword.



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-10-02 : 03:06:42
Or you can search to CROSSTAB or PIVOT here at SQLTeam.

Or click this link and look out for yellow highlighted words
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=55210&SearchTerms=CROSSTAB,PIVOT



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

Syima
Starting Member

13 Posts

Posted - 2007-10-02 : 03:12:16
yes, i'm using sql 2005-query analyzer to check my sql syntax, but i will have to translate it to another N-Niku SQL which is used in Clarity software. I'm afraid the keyword PIVOT is not recognized/supported in N-SQL. Is there other way to change the query?
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-10-02 : 03:32:50
Click to link provided above and look carefully for yellow hightlighted words.
Read the topics marked with yellow.



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

jackv
Master Smack Fu Yak Hacker

2179 Posts

Posted - 2007-10-03 : 06:13:08
A good article , covering sql 2000 and 2005
http://jdixon.dotnetdevelopersjournal.com/pivot_table_data_in_sql_server_2000_and_2005.htm

Jack Vamvas
--------------------
Search IT jobs from multiple sources- http://www.ITjobfeed.com/SQL
Go to Top of Page
   

- Advertisement -