troubleshooting Question

Could you point a way to group all the contents of the resultant UNION column to just one result line by using MSSQLServer?

Avatar of Eduardo Fuerte
Eduardo FuerteFlag for Brazil asked on
Microsoft SQL Server
8 Comments1 Solution35 ViewsLast Modified:
Hi Experts

Could you point a way to group all the contents of the resultant UNION column to just one result line by using MSSQLServer?

Accordingly to:
select top (1000)
   tbl_x.cIDOrder,
   tbl_x.cIDCompany,
   tbl_x.cCustomer,
   tbl_x.cIDCustomer,
   tbl_x.cName,
   tbl_x.cTerritoryName,
   tbl_x.cCondPagto,
   tbl_x.dCreated,
   tbl_x.dShipping,
   tbl_x.cCommunicationValue,  -- <<<<   All the cCommunicationValue(s) agruped at just one column
   tbl_x.nOrderTotalValue,
   tbl_x.cType,
   tbl_x.cPDFTitle,
   tbl_x.cBodyText,
   

from
(
    
   SELECT DISTINCT
         O.cIDOrder AS cIDOrder,
         O.cIDCompany AS cIDCompany,
         O.cIDCustomer + ' - ' + C.cCustomerName AS cCustomer,
         O.cIDCustomer AS cIDCustomer,
         C.cCustomerName AS cName,
         T.cTerritoryName AS cTerritoryName,
         GD_CP.cDescription AS cCondPagto,
         O.dCreated AS dCreated,
         O.dExpectedBilling AS dShipping,
         C1.cCommunicationValue AS cCommunicationValue, -- <<<<============
         O.nTotalValue AS nOrderTotalValue,
         'PEDIDO' AS cType,
         'Relatório do Pedido' AS cPDFTitle,
         'cópia do Pedido' AS cBodyText 
      FROM
         ...
      UNION
      SELECT DISTINCT
         O.cIDOrder AS cIDOrder,
         O.cIDCompany AS cIDCompany,
         O.cIDCustomer + ' - ' + C.cCustomerName AS cCustomer,
         O.cIDCustomer AS cIDCustomer,
         C.cCustomerName AS cName,
         T.cTerritoryName AS cTerritoryName,
         GD_CP.cDescription AS cCondPagto,
         O.dCreated AS dCreated,
         O.dExpectedBilling AS dShipping,
         US.cEmail AS cCommunicationValue,  -- <<<<============
         O.nTotalValue AS nOrderTotalValue,
         'PEDIDO' AS cType,
         'Relatório do Pedido' AS cPDFTitle,
         'cópia do Pedido' AS cBodyText 
      FROM
         ...
      UNION
      SELECT DISTINCT
         O.cIDOrder AS cIDOrder,
         O.cIDCompany AS cIDCompany,
         O.cIDCustomer + ' - ' + C.cCustomerName AS cCustomer,
         O.cIDCustomer AS cIDCustomer,
         C.cCustomerName AS cName,
         T.cTerritoryName AS cTerritoryName,
         GD_CP.cDescription AS cCondPagto,
         O.dCreated AS dCreated,
         O.dExpectedBilling AS dShipping,
         C1.cCommunicationValue AS cCommunicationValue, -- <<<<============
         O.nTotalValue AS nOrderTotalValue,
         'COTAÇÃO' AS cType,
         'Cotação' AS cPDFTitle,
         'cópia da Cotação' AS cBodyText 
      FROM
         ...

      UNION

      SELECT DISTINCT
            O.cIDOrder AS cIDOrder,
            O.cIDCompany AS cIDCompany,
            O.cIDCustomer + ' - ' + C.cCustomerName AS cCustomer,
            O.cIDCustomer AS cIDCustomer,
            C.cCustomerName AS cName,
            T.cTerritoryName AS cTerritoryName,
            GD_CP.cDescription AS cCondPagto,
            O.dCreated AS dCreated,
            O.dExpectedBilling AS dShipping,
            CO.cCommunicationValue as cCommunicationValue2, -- <<<<============
            O.nTotalValue AS nOrderTotalValue,
            'PEDIDO' AS cType,
            'Relatório do Pedido' AS cPDFTitle,
            'cópia do Pedido' AS cBodyText
         FROM
            ...
      ) tbl_x
The final query must to consider at just one column all the "emails" to send it by using just one email to all the recipient(s)

Thanks in advance
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 8 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros