I'm using SQL Server 2005 and trying to get data from 3 tables. I can get the (simple) information from the first two tables (shown in the code) but I'm not sure how to get the third part of the data into the query from the third table.
This returns the data as required (Customer #, Customer Name, Sales Person, Start Date)
I also need it to display the date of the customer's most recent order (if there is one) and how many days it's been since their last order. This should display "INACTIVE" if they have never placed an order. This data is in a 3rd table.
This was all working fine in a crystal report with a subreport, but I'm not sure how to convert it all into a SQL Server query.
Thanks for your help!
Code:
SELECT Customer.CustomerN AS '#', Customer.CustomerName AS 'Customer',
CASE WHEN Salesperson.Salesperson LIKE 'T %' OR Salesperson.Salesperson LIKE 'O %' THEN SUBSTRING (Salesperson.Salesperson, 3, LEN (Salesperson.Salesperson))
WHEN Salesperson.Salesperson LIKE 'Tie %' OR Salesperson.Salesperson LIKE 'Tbr %' OR Salesperson.Salesperson LIKE 'Obr %' THEN SUBSTRING (Salesperson.Salesperson, 5, LEN (Salesperson.Salesperson))
ELSE Salesperson.Salesperson
END AS 'Sales',
CONVERT(varchar,Customer.CustStartDate,101) AS 'Start'
FROM Customer Customer LEFT OUTER JOIN Salesperson Salesperson ON Customer.SalespersonN=Salesperson.SalespersonN
ORDER BY Customer.CustomerN
This returns the data as required (Customer #, Customer Name, Sales Person, Start Date)
I also need it to display the date of the customer's most recent order (if there is one) and how many days it's been since their last order. This should display "INACTIVE" if they have never placed an order. This data is in a 3rd table.
This was all working fine in a crystal report with a subreport, but I'm not sure how to convert it all into a SQL Server query.
Thanks for your help!