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 2005 Forums
 Transact-SQL (2005)
 Select distinct records for a textfield

Author  Topic 

cplusplus
Aged Yak Warrior

567 Posts

Posted - 2009-02-25 : 16:49:39
I am using the following select but i get multiple records with the same tiffile field, i am using distinct but its still gets multiple records.

field tiffile is a text field.

SELECT DISTINCT C.Tiffile, C.id,
D.ProgNO, E.ProjNO, F.ContractNO, A.RMID, A.SequenceNO,

case
when @LocLang = 'English' then L.EnglishText
when @LocLang = 'Spanish' then L.SpanishText
when @LocLang = 'Catalan' then L.CatalanText
end as EnglishText,


A.Deleted
FROM TablePM AS A JOIN TABUserAccess AS B ON (A.ProgID = B.ProgID and A.ProjID = B.ProjID and A.ContractID = B.ContractID and B.Userid = @Userid AND B.Module = 'PM') INNER JOIN
TAB_Programs D ON A.ProgID = D.ProgID INNER JOIN
TAB_Projects E ON A.ProjID = E.ProjID INNER JOIN
TAB_Contracts F ON A.ContractID = F.ContractID
INNER JOIN TAB_PickLists L on (A.Logtypeid = L.PickID and L.FieldLabelKey = 'lblLogType')
JOIN #TEMPFINDOCR AS C ON (A.RMID = C.type_id) WHERE A.Deleted = 0

Drop table #TEMPFINDOCR



Thank you very much for the help.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-02-25 : 17:05:17
You probably don't want to use DISTINCT and instead you probably need GROUP BY with an aggregate function.

It's hard to answer your question though with what you have provided. Show us a data example to make your issue more clear.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2009-02-25 : 17:23:31
Use ROW_NUMBER() Over (Partition by C.Tiffile Order by your choice)
Go to Top of Page
   

- Advertisement -