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)
 Distinct record on column

Author  Topic 

gangadhara.ms
Aged Yak Warrior

549 Posts

Posted - 2011-03-07 : 23:16:33
Dear All,

I am usign the below query but i need to fetch distinct records for date modified column.pls help

SELECT getdate(), SS.ID'employee_code','' 'employee_terr_code',
ISNULL((E.NameGiven+' '+ ISNULL(E.NameMiddle,'')+' '+E.Namefamily),'')'author',
h.DateModified 'created_date',
h.lid 'code',
'title_code='+isnull(T.TitleName,'NULL')+ ' '+
'Dcode='+isnull(LD.DCode,'NULL')+ ' '+
'category='+isnull(CS.Customer_Sub_type,'NULL')+' '+
'first_name='+isnull(h.namegiven,'NULL')+ ' '+
'initials='+ISNULL(h.NameMiddle,'NULL')+ ' ' +
'last_name='+isnull(H.namefamily,'NULL')+ ' '+
'graduation_year='+isnull(PD.graduation_year,'NULL')+ ' '+
'gender='+isnull(lg.gender,'NULL')+ ' '+
'phone_number='+ ISNULL(h.mobile,'NULL') as 'change_request'
FROM hearachy h
left outer join gender lg on h.gender_id = lg.id
left outer join Title T on T.ID=H.Title_ID
left outer join doc PD on PD.doctor_code=convert(int,h.legacyid)
left outer join cust CS on CS.Category_ID=h.Category_ID and CS.Specialty_ID=h.Specialty_ID
left outer join sesummatr SS on SS.ID=H.Session_ID
left outer join employee E on E.ID = SS.rep_ID
left outer join doctype LD on LD.CatID=h.CatID
WHERE h.DateModified >= @DateFrom -- and h.DateModified <=@todate
and h.country_Id = 61
and h.LegacyID IS NOT NULL
and h.legacyid not in (select pcode from jjreq where datesent > dateadd(dd,0,datediff(dd,0,getdate())))
and LD.Dodesc <> 'Registrar'
and SS.ID is not NULL

Thanks,
Gangadhara MS
SQL Developer and DBA

yadhu_cse
Constraint Violating Yak Guru

252 Posts

Posted - 2011-03-09 : 04:07:46
distinct h.DateModified make it first column an try
Go to Top of Page

pk_bohra
Master Smack Fu Yak Hacker

1182 Posts

Posted - 2011-03-09 : 07:07:48
quote:
Originally posted by yadhu_cse

distinct h.DateModified make it first column an try



Does column position makes any difference when you are using distint ?
Go to Top of Page
   

- Advertisement -