Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 8581

Re: Assistance with SQL query

$
0
0

Hi shachar

 

Thanks for help!

 

This is now working but problem is customers who have never been visited (where no Activity of 'Visit to Customer' Type exists) are being excluded by Query.

 

I would like all Customers who have a Visit Due date in CRD1 to be in query result even if no previous visit Activity exists .... in such cases 'Last Visit Date' should be empty field in results.

 

is this possible?

 

Regards,

Karen

 

 

--Customer visits due - due date for next standard visit due from UDF in Address also bringing in Last visit date from Visit Activity IF any such Visit Activities exist

SELECT T0.[CardName], T1.Address, T1.U_Territory, T1.U_NxtVisitDue, MAX(T2.Recontact) AS 'Last Visit Date'

FROM  OCRD T0 INNER JOIN CRD1 T1 on T1.CardCode=T0.CardCode

INNER JOIN OCLG T2 on T2.CardCode=T0.CardCode

WHERE DateDiff(dd,GetDate(), T1.U_NxtVisitDue) <0

and  T2.CntctType=21

GROUP BY T0.[CardName], T1.Address, T1.U_Territory, T1.U_NxtVisitDue


Viewing all articles
Browse latest Browse all 8581

Trending Articles