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.
| Author |
Topic |
|
deppi
Starting Member
3 Posts |
Posted - 2004-08-26 : 07:07:48
|
HI, How do I include a text (or ntext) field in a query that uses an aggregate function?I could not use text field in the group by clause. How do I do this in SQL Server? |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2004-08-26 : 07:55:59
|
| you can't. you'll need to use a select with out the text field, and the join it to another select in which you pick the text field you want to use.Go with the flow & have fun! Else fight the flow :) |
 |
|
|
Desmag
Starting Member
18 Posts |
Posted - 2006-02-02 : 11:40:18
|
| I have a similar problem. I need to count user's posts, but this means that I have to GROUP BY which is impossible because one of the columns is nText.Spirit1 mention join with another select. Is this the right approach?:SELECT TOP 1P1.Post_ID,P1.Post_Title,P1.Post_Author_Id,P1.Post_Date,P1.Post_Category,P1.Visible,COUNT(P1.Post_ID) AS Users_replies,P2.Post_BodyFROM tbl_Forum_Post P1INNER JOIN tbl_Forum_Post P2 ONP1.Post_Id = P2.Post_IdWHERE P1.Post_Id = @Thread And P1.Visible = 1GROUP BYP1.Post_ID,P1.Post_Title,P1.Post_Author,P1.Post_Date,P1.Post_Category,P1.Visible |
 |
|
|
stephe40
Posting Yak Master
218 Posts |
Posted - 2006-02-02 : 11:56:06
|
I am guessing you want to display the post and the a count of how many user replies were made for that post. Try this:select P1.Post_ID, P1.Post_Title, P1.Post_Author_Id, P1.Post_Date, P1.Post_Category, P1.Visible, p2.cntfrom tbl_Forum_Post P1 inner join (select px.postID, count(*) as cnt from tbl_Forum_Post px group by px.postID) p2 on p1.postId = p2.postIDWHERE P1.Post_Id = @Thread And P1.Visible = 1 - Eric |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-02-03 : 03:30:04
|
| If you want to include text column in Group by you need to convert that to varchar datatype which may not give you perfect resultMadhivananFailing to plan is Planning to fail |
 |
|
|
Desmag
Starting Member
18 Posts |
Posted - 2006-02-07 : 20:02:18
|
| Thanks guys! stephe40 - your method solved my problem :) |
 |
|
|
|
|
|
|
|