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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 select query using distinct for ID field error

Author  Topic 

reddymade
Posting Yak Master

165 Posts

Posted - 2005-08-02 : 16:27:06
I have the following query:
I want to use distinct which is in table A.CNID
i want to use distinct A.CNID,A.* in select query

I am getting following error, Can you please help:
Server: Msg 8163, Level 16, State 3, Line 1
The text, ntext, or image data type cannot be selected as DISTINCT.


SELECT Distinct A.CNID,A.*,C.ProgNO AS ProgNO, D.ProjNO AS ProjNO, E.ContractNO AS ContractNO, B.AccessMode
FROM TAB_ccsNetCN A INNER JOIN
TAB_ccsNetUserAccess B ON A.ProgID = B.ProgID AND A.ProjID = B.ProjID
AND A.ContractID = B.ContractID INNER JOIN
TAB_ccsNetPrograms C ON C.ProgID = A.ProgID INNER JOIN
TAB_ccsNetProjects D ON D.ProjID = A.ProjID INNER JOIN
TAB_ccsNetContracts E ON E.ContractID = A.ContractID
WHERE B.UserName = 'JOHN' AND A.CNID = 508 and a.deleted=0 AND B.Deleted = 0 AND B.ccsNetModule = 'CN'


If i don't use the distinct it is getting 5 records for same id 508. i want to get only one record with the above query, but it is throwing an error for the distinct.

Thank you very much for the help.

AndyB13
Aged Yak Warrior

583 Posts

Posted - 2005-08-02 : 16:55:03
It would appear you have a column in 'TAB_ccsNetCN' table which is as the error states is of the datatype text etc. Which cant be used with distinct.
Do you need the text column in your query?

Write your SELECT statement with the columns you require and not SELECT *. This query may also cause your app to "crash" because of ambiguos column names ie CNID x 2.

You could use TOP 1 or SET ROWCOUNT 1

Andy

Beauty is in the eyes of the beerholder
Go to Top of Page
   

- Advertisement -