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 |
|
NickC
Yak Posting Veteran
68 Posts |
Posted - 2010-05-24 : 06:42:36
|
| Hello I am trying to create a query for an MI Report but struggling. This in its current state is pulling in duplicates of i.insurance_ref when I only want it to display one - I understand it could be because other fields are different but I only need the max() or if not possible then just one of them.This is what I have so far:select distincti.insurance_ref as Policy_Number, p.name as Agent_Name, ad.address1 as Address_1, ad.address2 as Address_2, ad.address3 as Address_3, ad.address4 as Address_4, ad.postal_code as Postal_Code, c.area_code as Area_Code, c.number as Number, c.extension as Extension, sp.first_applicant_title as Title, sp.first_applicant_forename as Forename, sp.first_applicant_surname as Surname, i.cover_start_date as Cover_Start_Date, i.renewal_date as Renewal_Date, fs.date_created as System_Date_Created, sp.product_variant as Product_Variant, i.annual_premium as Annual_Premium, i.this_premium as Monthly_Premium,ref.description as Referral_Descriptionfrom plusone_general sp inner join plusone_policy_binder spbon sp.plusone_policy_binder_id = spb.plusone_policy_binder_idinner join gis_policy_link plon spb.plusone_policy_binder_id = pl.gis_policy_link_idinner join risk ron pl.risk_id = r.risk_cntinner join insurance_file_risk_link rlon r.risk_cnt = rl.risk_cntinner join insurance_file ion rl.insurance_file_cnt = i.insurance_file_cntinner join insurance_file_type ton i.insurance_file_type_id = t.insurance_file_type_idinner join insurance_file_system fson i.insurance_file_cnt = fs.insurance_file_cntinner join party p on i.lead_agent_cnt = p.party_cntinner join party_address_usage pauon p.party_cnt = pau.party_cntinner join address adon pau.address_cnt = ad.address_cntinner join party_contact_usage pcuon p.party_cnt = pcu.party_cntinner join contact con pcu.contact_cnt = c.contact_cntinner join Plusone_referrals refon spb.plusone_policy_binder_id = ref.plusone_policy_binder_idwhere i.cover_start_date = '2009-01-01' AND i.renewal_date = '2009-02-01' |
|
|
sodeep
Master Smack Fu Yak Hacker
7174 Posts |
Posted - 2010-05-24 : 07:59:31
|
| Use ROW_NUMBER() function. |
 |
|
|
|
|
|
|
|