I think Roy answered your question. I'd like to ask, can you get OrderMonth
=5 and recdate '20070701'?
I meant 5- May and recdate is July?
This is a sample data, what would be output?
create table tableA (ClientName varchar(50) , OrderMonth int , Recdate
datetime)
create table tableB (row_id int not null primary key, ClientName varchar(50)
, ClientAdd varchar(50))
insert into TableA values ('John Smith',1 ,'20070101')
insert into TableA values ('Bill Clinton',2 ,'20070102')
insert into TableA values ('Bill Clinton',3 ,'20070103')
insert into TableA values ('Vladimir Putin',1 ,'20070110')
insert into TableB values (1,'John Smith','Usa 57 Street')
insert into TableB values (2,'Bill Clinton','Usa Arkansas')
insert into TableB values (3,'Vladimir Putin','Moscow Kremlin')
---goes a new order
insert into TableA values ('Vladimir Putin',1 ,'20060101')
[quoted text, click to view] >> >address). Is there anywhere I could create a script to retrive a list
>> >client
>> >whose order that I did not receive during the past six month as well as
>> >the
>> >order month that I did not receive them.
select * from TableA where not exists
( select * from TableB where TableA.ClientName =TableB.ClientName and
TableA.Recdate >= dateadd(month,-6,getdate()))
[quoted text, click to view] "qjlee" <qjlee@discussions.microsoft.com> wrote in message
news:C2A299CC-1D92-4D51-96E4-E91821566120@microsoft.com...
>I think there is another way to script it without have to create the month
> table.
> Month can be calculated by (current month - 1), (current month -2 ), etc.
> then for each month, find out those clients who are in table A (client
> information table, which is a list of all clients) but not in table B
> (order
> information table). If I want do it this way, how to script it?
>
> Thanks,
>
> qjlee
>
> "Roy Harvey" wrote:
>
>> I am going to assume a Months table exists, keyed by a datetime with
>> one row for the first day of each month. I will also assume that
>> OrderMonth is in the same format.
>>
>> Something along these lines should do the job.
>>
>> SELECT C.ClientName, M.CalendarMonth
>> FROM Clients as C CROSS JOIN Months as M
>> WHERE NOT EXISTS
>> (select * from Orders as O
>> where O.ClientName = C.ClientName
>> and O.OrderMonth = Months.CalendarMonth)
>> AND datediff(month, M.CalendarMonth, getdate()) between 1 and 6
>>
>> Roy Harvey
>> Beacon Falls, CT
>>
>> On Sat, 27 Jan 2007 19:00:00 -0800, qjlee
>> <qjlee@discussions.microsoft.com> wrote:
>>
>> >Every week, I receive one order from each of my three clients. When
>> >the
>> >order is received, the Client Name (ClientName) and order month
>> >(OrderMonth)
>> >and receive date (Recdate) entered into a table called A. Client
>> >information
>> >is stored in Table B, ClientName (Name of the client) amd ClientAdd
>> >(Client's
>> >address). Is there anywhere I could create a script to retrive a list
>> >client
>> >whose order that I did not receive during the past six month as well as
>> >the
>> >order month that I did not receive them.
>> >
>> >Thanks,
>>