group by - SQL Removing Duplicate Result with Left Join -


i've got code if pulling info 2 different tables, , i'm getting duplicates. i've tried distinct in select statement, lots of errors "ntext data type cannot selected distinct because not comparable."

so next attempt try group by, errors "column person.pers_firstname invalid in select list because not contained in either aggregate function or group clause.

so records have multiple relationship fields, it's problem because records have none, 1 or more 1 relationship (the options null, project engineer, project owner, or project contractor). current code shows null , project engineer, if there's records other 2 excluded. if include other relationship descriptions duplicates.

select      rtrim(isnull(pers_firstname, '')) + ' ' + rtrim(isnull(pers_lastname, ''))        pers_fullname,      rtrim(isnull(oppocomp.comp_phonecountrycode, '')) + ' ' + rtrim(isnull(oppocomp.comp_phoneareacode, '')) + ' ' + rtrim(isnull(oppocomp.comp_phonenumber, '')) comp_phonefullnumber,     rtrim(isnull(oppocomp.comp_faxcountrycode, '')) + ' ' + rtrim(isnull(oppocomp.comp_faxareacode, '')) + ' ' + rtrim(isnull(oppocomp.comp_faxnumber, '')) comp_faxfullnumber,      rtrim(isnull(pers_phonecountrycode, '')) + ' ' + rtrim(isnull(pers_phoneareacode, '')) + ' ' + rtrim(isnull(pers_phonenumber, '')) pers_phonefullnumber,      rtrim(isnull(pers_faxcountrycode, '')) + ' ' + rtrim(isnull(pers_faxareacode, '')) + ' ' + rtrim(isnull(pers_faxnumber, '')) pers_faxfullnumber,      opportunity.*, oppocomp.comp_name, oppocomp.comp_territory, oppocomp.comp_emailaddress,     oppocomp.comp_companyid, oppocomp.comp_secterr, oppocomp.comp_createdby,     oppocomp.comp_primaryuserid, terr_caption, pers_title, pers_emailaddress, pers_secterr,     pers_createdby, pers_personid, pers_primaryuserid, chan_description,     oppocomp.comp_channelid, (oppo_base_currency.curr_currencyid) oppo_weightedforecast_cid,     pers_channelid ((oppo_forecast / oppo_forecast_currency.curr_rate) * oppo_certainty / 100) oppo_weightedforecast,      oppo_primaryaccountid acc_accountid, rend_notes, renl_description,     relcomp.comp_name rela_companyname  opportunity  left join person on oppo_primarypersonid = pers_personid  left join company oppocomp on oppo_primarycompanyid = comp_companyid  left join territories on oppo_secterr = terr_territoryid  left join channel on chan_channelid = oppo_channelid  left join relatedentitydata on oppo_opportunityid = rend_entity1id  left join relatedentitylinks on rend_relatedentitylinkid = renl_relatedentitylinkid  left join company relcomp on rend_entity2id = relcomp.comp_companyid  left join currency oppo_forecast_currency on oppo_forecast_cid = oppo_forecast_currency.curr_currencyid  left join currency oppo_base_currency       on oppo_base_currency.curr_currencyid = (                 select cast(cast(parm_value nchar) integer)                    custom_sysparams                  parm_name = 'basecurrency'             )  oppo_deleted null   , (renl_description null or renl_description = 'project engineer') 


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -