Ok...i have another query that I am working on and wanted to see if I can get some help from experts on here
I have a query (below) that I need to run against Business Partners and pull out address information. We have a single "Bill To", but can have several "Ship To" addresses. I want to get results of all the ship to addresses and have the "Bill To" entered in each line of the "Ship To" addresses.
Here is what I have pieced together:
SELECT
T1.[CardCode] AS "CAccountNum",
(SELECT distinct t0.cardname from crd1 T3 inner join crd1 t4 on t3.cardcode = t0.cardcode where t3.address like 'bill%%') AS "CCompanyName",
(SELECT distinct T1.[Street] from crd1 T3 inner join crd1 t4 on t3.cardcode = t0.cardcode where t3.address like 'bill%%' AND T1.[AdresType]='B') AS "CAddress1",
T1.[City] AS "CCity",
(SELECT distinct t1.[STATE] from crd1 T3 inner join crd1 t4 on t3.cardcode = t0.cardcode where t3.Adrestype = 'B') AS "CSTATE",
T1.[ZIPCODE] AS "CZip",
T1.[COUNTRY] AS "CCountry",
T1.[CardCode] AS "StoreAccountNum",
T1.[Street] AS "StoreName",
T1.[Block] AS "StoreAddress1",
T1.[City] AS "StoreCity",
T1.[State] AS "StoreState",
T1.[ZipCode] AS "StoreZip",
T1.[Country] AS "StoreCountry",
T0.[slpcode] AS "srCode"
FROM
OCRD T0
INNER JOIN CRD1 T1 ON T0.[CardCode] = T1.[CardCode]
INNER JOIN crd1 T ON T0.[CardCode] = T1.[CardCode]
WHERE
t1.cardcode='37891' AND
(T0.[GroupCode] IN ('120','116','117','118','122','106')) AND
(t0.[CardType]='C') AND
T0.[CreateDate] >'12/31/12'
Order BY t0.cardcode
Here is what I get: I want this to be a single line if I only have 1 ship to address, or 2 lines if i have 2 ship to, etc....
Any help would be greatly appreciated to clean this one up! Thanks!