Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If i understood this correctly u are trying to modify the view to get the desired output,below is the code for it</p> <pre><code>SELECT t2.cardcode as 'BP_Code', --t0.Recontact as 'Date', t2.CardName as 'BP_Name', SubString(T3.Name,1,2) as 'Salesman', replace(T0.Street,',',' ') as 'Street_Address', T0.City, T0.State, SUM(CASE WHEN YEAR(t0.recontact) = 2011 THEN convert(decimal(10,2),t0.U_sold) ELSE 0 END) AS 'Year2011', SUM(CASE WHEN YEAR(t0.recontact) = 2012 THEN convert(decimal(10,2),t0.U_sold) ELSE 0 END) AS 'Year2012', SUM(CASE WHEN YEAR(t0.recontact) = 2013 THEN convert(decimal(10,2),t0.U_sold) ELSE 0 END) AS 'Year2013', convert(decimal(10,2),SUM(t0.U_sold)) as 'Total_Sold' From OCLG t0 -- OCLG is Activities inner join OCRD t2 -- OCRD is Customer Definitions on T0.cardcode like t2.cardcode inner join OCLS t3 -- OCLS is Activity Definitions on T0.CntctSbjct=T3.Code where t0.U_sold &gt; 0 and T0.CntctSbjct=T3.Code and T0.CardCode=T2.CardCode and T0.CntctType='3' and t2.CardCode = 'a239' --This was added to simplify output and T0.Recontact &gt;= Convert(date, '2011-01-01' ) and T0.Recontact &lt;= Convert(date, '2013-12-31' ) group by t2.cardcode, t0.city, t0.state, replace(T0.Street,',',' '), t2.CardName, SubString(T3.Name,1,2) order by t2.CardCode </code></pre> <p>all I did was to correct your groupby clause, you were getting multiple records due to t0.Recontact in group by.</p> <p>If you have multiple values in t0.city, t0.state, replace(T0.Street,',',' '), t2.CardName, SubString(T3.Name,1,2) columns for a BP_Code and u want to pick one of the values of these columns then use below code </p> <pre><code>SELECT t2.cardcode as 'BP_Code', --t0.Recontact as 'Date', max(t2.CardName) as 'BP_Name', max(SubString(T3.Name,1,2)) as 'Salesman', max(replace(T0.Street,',',' ')) as 'Street_Address', max(T0.City) City, max(T0.State) State, SUM(CASE WHEN YEAR(t0.recontact) = 2011 THEN convert(decimal(10,2),t0.U_sold) ELSE 0 END) AS 'Year2011', SUM(CASE WHEN YEAR(t0.recontact) = 2012 THEN convert(decimal(10,2),t0.U_sold) ELSE 0 END) AS 'Year2012', SUM(CASE WHEN YEAR(t0.recontact) = 2013 THEN convert(decimal(10,2),t0.U_sold) ELSE 0 END) AS 'Year2013', convert(decimal(10,2),SUM(t0.U_sold)) as 'Total_Sold' From OCLG t0 -- OCLG is Activities inner join OCRD t2 -- OCRD is Customer Definitions on T0.cardcode like t2.cardcode inner join OCLS t3 -- OCLS is Activity Definitions on T0.CntctSbjct=T3.Code where t0.U_sold &gt; 0 and T0.CntctSbjct=T3.Code and T0.CardCode=T2.CardCode and T0.CntctType='3' and t2.CardCode = 'a239' --This was added to simplify output and T0.Recontact &gt;= Convert(date, '2011-01-01' ) and T0.Recontact &lt;= Convert(date, '2013-12-31' ) group by t2.cardcode order by t2.CardCode </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload