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 |
|
BendJoe
Posting Yak Master
128 Posts |
Posted - 2008-10-21 : 11:28:59
|
| The text data type cannot be selected as DISTINCT because it is not comparable.SELECT distinct A.ArticleID,A.ArticleGUID,A.Title,A.ArticleContent,A.WrittenByUserID,A.ApprovedByUserID, A.ActiveDate,A.TerminationDate,A.SortOrder,A.SecurityLevel,A.DateAdded,A.DateUpdated,A.UserAdded,A.UserUpdated,B.GroupID INTO #ArticleGroupInfo FROM #Articles A left outer join ArticleGroupLink B ON A.ArticleID=B.ArticleID;How can I fix this? |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-10-21 : 11:32:12
|
| If you're using sql 2005, try converting text field to varchar(max). If sql 2000 or earlier and if you're sure that length of data in field falls within 800 characters, try casting to varchar(8000) |
 |
|
|
BendJoe
Posting Yak Master
128 Posts |
Posted - 2008-10-21 : 11:58:08
|
| error is gone.But my query logic is wrong. I need to get a result from two tables.I have an Article Table and a Group table . In this case Article can belong to many groups but I need it in the result only once.Article TableArticleID,ContentetcGroup Table GroupID,ArticleID etcI need in the result ArticleID,Content,GroupID ArticleID must be unique how can I do this? |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-10-21 : 12:01:31
|
quote: Originally posted by BendJoe error is gone.But my query logic is wrong. I need to get a result from two tables.I have an Article Table and a Group table . In this case Article can belong to many groups but I need it in the result only once.Article TableArticleID,ContentetcGroup Table GroupID,ArticleID etcI need in the result ArticleID,Content,GroupID ArticleID must be unique how can I do this?
SELECT a.ArticleID,a.Content,g.GroupIDFROM Article aINNER JOIN Group gON g.ArticleID=a.ArticleIDINNER JOIN (SELECT ArticleID,MAX(GroupID) AS MaxGroup FROM Group GROUP BY ArticleID)g1ON g1.ArticleID=g.ArticleIDAND g1.MaxGroup=g.GroupID |
 |
|
|
|
|
|
|
|