Afternoon all,
I'm trying to output all data from a table and specific data from a joined table, I seem to be struggeling and can't get my head around it.
CREATE TABLE [dbo].[Customers](
[C_ID] [int] NOT NULL,
[C_Name] [nvarchar](20) NOT NULL,
[C_Status] [nvarchar](20) NOT NULL,
[C_Type] [nvarchar](20) NOT NULL,
);
INSERT INTO Customers(C_ID, C_Name, C_Status, C_Type)
VALUES
('1000', 'John', 'Live', 'Telephone'),
('1001', 'Jane', 'Live', 'In Person'),
('1002', 'Bob', 'Live', 'Email')
('1003', 'Emma', 'Live', 'Catalogue')
;
CREATE TABLE [dbo].[Customer_Contact](
[CC_ID] [int] NOT NULL,
[CC_CustID] [int] NOT NULL,
[CC_Notes] [nvarchar](20) NOT NULL
);
INSERT INTO Customer_Contact(CC_CustID, CC_Notes)
VALUES
('1000', 'Phone call to discuss blar'),
('1000', 'Emailed customer to advise them blar'),
('1000', 'Sent SMS to warn item will be late'),
('1001', 'Phone call to chase for details'),
('1001', 'Email to advise to price change'),
('1002', 'Phone call to place order')
;
The Query I currently have, which doesn't out put the correct data is:
SELECT C_Name, C_Status, C_Type, CC_Notes
FROM Customers
JOIN Customer_Contact ON C_ID = CC_CustID
WHERE CC_Notes LIKE '%Phone%'
I would like to get something like:
C_Name, C_Status, C_Type, CC_Notes
John, Live, Telephone, Phone call to discuss blar
Jane, Live, In Person, Phone call to chase for details
Bob, Live, Email, Phone call to place order
Emma, Live, Catalogue, Null
It would be really nice to go one step further, but not sure its possible, and output 2 different notes on the same line to get something like this:
C_Name, C_Status, C_Type, CC_Notes_Phone, CC_Notes_Email
John, Live, Telephone, Phone call to discuss blar, Emailed customer to advise them blar
Jane, Live, In Person, Phone call to chase for details, Email to advise to price change
Bob, Live, Email, Phone call to place order, Null
Emma, Live, Catalogue, Null, Null
Hope that makes sense...
Many thanks
Dave